applied patch #45967 by Gisella Bronzetti: support for XSSFPrintSetup object

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@703778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2008-10-12 10:25:58 +00:00
parent b4e74b306c
commit bff1825f78
12 changed files with 941 additions and 29 deletions

View File

@ -0,0 +1,31 @@
package org.apache.poi.xssf.usermodel.examples;
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class FitSheetToOnePage {
public static void main(String[]args) throws Exception{
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("format sheet");
PrintSetup ps = sheet.getPrintSetup();
sheet.setAutobreaks(true);
ps.setFitHeight((short)1);
ps.setFitWidth((short)1);
// Create various cells and rows for spreadsheet.
FileOutputStream fileOut = new FileOutputStream("fitSheetToOnePage.xlsx");
wb.write(fileOut);
fileOut.close();
}
}

View File

@ -67,13 +67,7 @@ public interface PrintSetup {
*/
void setFitHeight(short height);
/**
* Sets the options flags. Not advisable to do it directly.
* @param options The bit flags for the options
*/
void setOptions(short options);
/**
/**
* Set whether to go left to right or top down in ordering
* @param ltor left to right
*/
@ -181,12 +175,6 @@ public interface PrintSetup {
*/
short getFitHeight();
/**
* Returns the bit flags for the options.
* @return bit flags for the options
*/
short getOptions();
/**
* Returns the left to right print order.
* @return left to right print order

View File

@ -0,0 +1,65 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
/**
* Specifies printed page order.
*
* @author Gisella Bronzetti
*/
public enum PageOrder {
/**
* Order pages vertically first, then move horizontally.
*/
DOWN_THEN_OVER(STPageOrder.DOWN_THEN_OVER),
/**
* Order pages horizontally first, then move vertically
*/
OVER_THEN_DOWN(STPageOrder.OVER_THEN_DOWN);
private STPageOrder.Enum order;
PageOrder(STPageOrder.Enum order) {
this.order = order;
}
/**
* Returns value of pages order
*
* @return String value of pages order
*/
public STPageOrder.Enum getValue() {
return order;
}
public static PageOrder valueOf(STPageOrder.Enum pageOrder) {
switch (pageOrder.intValue()) {
case STPageOrder.INT_DOWN_THEN_OVER:
return DOWN_THEN_OVER;
case STPageOrder.INT_OVER_THEN_DOWN:
return OVER_THEN_DOWN;
}
throw new RuntimeException("PageOrder value [" + pageOrder + "] not supported");
}
}

View File

@ -17,15 +17,28 @@
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.Sheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
public class XSSFWorksheet extends XSSFSheet implements Sheet{
public XSSFWorksheet(CTSheet sheet, CTWorksheet worksheet,
XSSFWorkbook workbook) {
super(sheet, worksheet, workbook);
}
/**
* The enumeration value indicating the possible paper size for a sheet
*
* @author Daniele Montagni
*/
public enum PaperSize {
LETTER_PAPER,
LETTER_SMALL_PAPER,
TABLOID_PAPER,
LEDGER_PAPER,
LEGAL_PAPER,
STATEMENT_PAPER,
EXECUTIVE_PAPER,
A3_PAPER,
A4_PAPER,
A4_SMALL_PAPER,
A5_PAPER,
B4_PAPER,
B5_PAPER,
FOLIO_PAPER,
QUARTO_PAPER,
STANDARD_PAPER_10_14,
STANDARD_PAPER_11_17;
}

View File

@ -0,0 +1,73 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments;
/**
* These enumerations specify how cell comments shall be displayed for paper printing purposes.
*
* @author Gisella Bronzetti
*/
public enum PrintCellComments {
/**
* Do not print cell comments.
*/
NONE(STCellComments.NONE),
/**
* Print cell comments as displayed.
*/
AS_DISPLAYED(STCellComments.AS_DISPLAYED),
/**
* Print cell comments at end of document.
*/
AT_END(STCellComments.AT_END);
private STCellComments.Enum comments;
PrintCellComments(STCellComments.Enum comments) {
this.comments = comments;
}
/**
* Returns comments of cell
*
* @return String comments of cell
*/
public STCellComments.Enum getValue() {
return comments;
}
public static PrintCellComments valueOf(STCellComments.Enum cellComment) {
switch (cellComment.intValue()) {
case STCellComments.INT_AS_DISPLAYED:
return AS_DISPLAYED;
case STCellComments.INT_AT_END:
return AT_END;
case STCellComments.INT_NONE:
return NONE;
}
throw new RuntimeException("PrintCellComments: value [" + cellComment + "] not supported");
}
}

View File

@ -0,0 +1,77 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation;
/**
* The enumeration value indicating the print orientation for a sheet.
*
* @author Gisella Bronzetti
*/
public enum PrintOrientation {
/**
* orientation not specified
*/
DEFAULT(STOrientation.DEFAULT),
/**
* portrait orientation
*/
PORTRAIT(STOrientation.PORTRAIT),
/**
* landscape orientations
*/
LANDSCAPE(STOrientation.LANDSCAPE);
private STOrientation.Enum orientation;
PrintOrientation(STOrientation.Enum orientation) {
this.orientation = orientation;
}
/**
* Returns value of the orientation
*
* @return String value of the orientation
*/
public STOrientation.Enum getValue() {
return orientation;
}
public static PrintOrientation valueOf(STOrientation.Enum orient) {
switch (orient.intValue()) {
case STOrientation.INT_DEFAULT:
return DEFAULT;
case STOrientation.INT_LANDSCAPE:
return LANDSCAPE;
case STOrientation.INT_PORTRAIT:
return PORTRAIT;
/*
default:
return DEFAULT;
*/
}
throw new RuntimeException("Orientation value [" + orient + "] not supported");
}
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.xssf.usermodel;
/**
* All know type of automatic shapes in DrawingML
* All known types of automatic shapes in DrawingML
*
* @author Yegor Kozlov
*/

View File

@ -45,7 +45,7 @@ public class XSSFDrawing extends POIXMLDocumentPart {
/**
* Create a new SpreadsheetML drawing
*
* @see org.apache.poi.xssf.usermodel.XSSFWorksheet#createDrawingPatriarch()
* @see org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch()
*/
public XSSFDrawing() {
super(null, null);

View File

@ -0,0 +1,455 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
/**
* Page setup and page margins settings for the worksheet.
*/
public class XSSFPrintSetup implements PrintSetup {
private CTWorksheet ctWorksheet;
private CTPageSetup pageSetup;
private CTPageMargins pageMargins;
public XSSFPrintSetup(CTWorksheet worksheet) {
if (worksheet == null) throw new NullPointerException("");
this.ctWorksheet = worksheet;
this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();
}
public XSSFPrintSetup(XSSFSheet sheet) {
this(sheet.getWorksheet());
}
public XSSFPrintSetup(CTPageSetup pageSetup, CTPageMargins pageMargins) {
this.pageMargins = pageMargins;
this.pageSetup = pageSetup;
}
/**
* Set the paper size.
*
* @param size the paper size.
*/
public void setPaperSize(short size) {
pageSetup.setPaperSize(size);
}
/**
* Set the paper size as enum value.
*
* @param size value for the paper size.
*/
public void setPaperSize(PaperSize size) {
setPaperSize((short) (size.ordinal() + 1));
}
/**
* Set the scale.
* Valid values range from 10 to 400.
* This setting is overridden when fitToWidth and/or fitToHeight are in use
*
* @param scale the scale to use
*/
public void setScale(short scale) {
if (scale < 10 || scale > 400) throw new RuntimeException("Scale value not accepted: you must choose a value between 10 and 400.");
pageSetup.setScale(scale);
}
/**
* Set the page numbering start.
* Page number for first printed page. If no value is specified, then 'automatic' is assumed.
*
* @param start the page numbering start
*/
public void setPageStart(short start) {
pageSetup.setFirstPageNumber(start);
}
/**
* Set the number of pages wide to fit the sheet in
*
* @param width the number of pages
*/
public void setFitWidth(short width) {
pageSetup.setFitToWidth(width);
}
/**
* Set the number of pages high to fit the sheet in
*
* @param height the number of pages
*/
public void setFitHeight(short height) {
pageSetup.setFitToHeight(height);
}
/**
* Set whether to go left to right or top down in ordering
*
* @param ltor left to right
*/
public void setLeftToRight(boolean ltor) {
if (ltor)
setPageOrder(PageOrder.OVER_THEN_DOWN);
}
/**
* Set whether to print in landscape
*
* @param ls landscape
*/
public void setLandscape(boolean ls) {
if (ls)
setOrientation(PrintOrientation.LANDSCAPE);
}
/**
* Use the printer's defaults settings for page setup values and don't use the default values
* specified in the schema. For example, if dpi is not present or specified in the XML, the
* a plication shall not assume 600dpi as specified in the schema as a default and instead
* shall let the printer specify the default dpi.
*
* @param valid Valid
*/
public void setValidSettings(boolean valid) {
pageSetup.setUsePrinterDefaults(valid);
}
/**
* Set whether it is black and white
*
* @param mono Black and white
*/
public void setNoColor(boolean mono) {
pageSetup.setBlackAndWhite(mono);
}
/**
* Set whether it is in draft mode
*
* @param d draft
*/
public void setDraft(boolean d) {
pageSetup.setDraft(d);
}
/**
* Print the include notes
*
* @param printnotes print the notes
*/
public void setNotes(boolean printnotes) {
if (printnotes)
pageSetup.setCellComments(PrintCellComments.AS_DISPLAYED.getValue());
}
/**
* Set no orientation.
*
* @param orientation Orientation.
*/
public void setNoOrientation(boolean orientation) {
if (orientation) {
setOrientation(PrintOrientation.DEFAULT);
}
}
/**
* Set whether to use page start
*
* @param page Use page start
*/
public void setUsePage(boolean page) {
pageSetup.setUseFirstPageNumber(page);
}
/**
* Sets the horizontal resolution.
*
* @param resolution horizontal resolution
*/
public void setHResolution(short resolution) {
pageSetup.setHorizontalDpi(resolution);
}
/**
* Sets the vertical resolution.
*
* @param resolution vertical resolution
*/
public void setVResolution(short resolution) {
pageSetup.setVerticalDpi(resolution);
}
/**
* Sets the header margin.
*
* @param headermargin header margin
*/
public void setHeaderMargin(double headermargin) {
pageMargins.setHeader(headermargin);
}
/**
* Sets the footer margin.
*
* @param footermargin footer margin
*/
public void setFooterMargin(double footermargin) {
pageMargins.setFooter(footermargin);
}
/**
* Sets the number of copies.
*
* @param copies number of copies
*/
public void setCopies(short copies) {
pageSetup.setCopies(copies);
}
/**
* Orientation of the page: landscape - portrait.
*
* @param orientation - Orientation of the page
* @see PrintOrientation
*/
public void setOrientation(PrintOrientation orientation) {
pageSetup.setOrientation(orientation.getValue());
}
/**
* Orientation of the page: landscape - portrait.
*
* @return Orientation of the page
* @see PrintOrientation
*/
public PrintOrientation getOrientation() {
return (pageSetup.getOrientation() == null) ? null : PrintOrientation.valueOf(pageSetup.getOrientation());
}
public PrintCellComments getCellComment() {
return (pageSetup.getCellComments() == null) ? null : PrintCellComments.valueOf(pageSetup.getCellComments());
}
/**
* Set print page order.
*
* @param pageOrder
*/
public void setPageOrder(PageOrder pageOrder) {
pageSetup.setPageOrder(pageOrder.getValue());
}
/**
* get print page order.
*
* @return PageOrder
*/
public PageOrder getPageOrder() {
return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder());
}
/**
* Returns the paper size.
*
* @return short - paper size
*/
public short getPaperSize() {
return (short) pageSetup.getPaperSize();
}
/**
* Returns the paper size as enum.
*
* @return PaperSize paper size
* @see PaperSize
*/
public PaperSize getPaperSizeEnum() {
return PaperSize.values()[((int) getPaperSize() - 1)];
}
/**
* Returns the scale.
*
* @return short - scale
*/
public short getScale() {
return (short) pageSetup.getScale();
}
/**
* Set the page numbering start.
* Page number for first printed page. If no value is specified, then 'automatic' is assumed.
*
* @return page number for first printed page
*/
public short getPageStart() {
return (short) pageSetup.getFirstPageNumber();
}
/**
* Returns the number of pages wide to fit sheet in.
*
* @return number of pages wide to fit sheet in
*/
public short getFitWidth() {
return (short) pageSetup.getFitToWidth();
}
/**
* Returns the number of pages high to fit the sheet in.
*
* @return number of pages high to fit the sheet in
*/
public short getFitHeight() {
return (short) pageSetup.getFitToHeight();
}
/**
* Returns the left to right print order.
*
* @return left to right print order
*/
public boolean getLeftToRight() {
return getPageOrder() == PageOrder.OVER_THEN_DOWN;
}
/**
* Returns the landscape mode.
*
* @return landscape mode
*/
public boolean getLandscape() {
return getOrientation() == PrintOrientation.LANDSCAPE;
}
/**
* Use the printerÕs defaults settings for page setup values and don't use the default values
* specified in the schema. For example, if dpi is not present or specified in the XML, the
* application shall not assume 600dpi as specified in the schema as a default and instead
* shall let the printer specify the default dpi.
*
* @return valid settings
*/
public boolean getValidSettings() {
return pageSetup.getUsePrinterDefaults();
}
/**
* Returns the black and white setting.
*
* @return black and white setting
*/
public boolean getNoColor() {
return pageSetup.getBlackAndWhite();
}
/**
* Returns the draft mode.
*
* @return draft mode
*/
public boolean getDraft() {
return pageSetup.getDraft();
}
/**
* Returns the print notes.
*
* @return print notes
*/
public boolean getNotes() {
return getCellComment() == PrintCellComments.AS_DISPLAYED;
}
/**
* Returns the no orientation.
*
* @return no orientation
*/
public boolean getNoOrientation() {
return getOrientation() == PrintOrientation.DEFAULT;
}
/**
* Returns the use page numbers.
*
* @return use page numbers
*/
public boolean getUsePage() {
return pageSetup.getUseFirstPageNumber();
}
/**
* Returns the horizontal resolution.
*
* @return horizontal resolution
*/
public short getHResolution() {
return (short) pageSetup.getHorizontalDpi();
}
/**
* Returns the vertical resolution.
*
* @return vertical resolution
*/
public short getVResolution() {
return (short) pageSetup.getVerticalDpi();
}
/**
* Returns the header margin.
*
* @return header margin
*/
public double getHeaderMargin() {
return pageMargins.getHeader();
}
/**
* Returns the footer margin.
*
* @return footer margin
*/
public double getFooterMargin() {
return pageMargins.getFooter();
}
/**
* Returns the number of copies.
*
* @return number of copies
*/
public short getCopies() {
return (short) pageSetup.getCopies();
}
}

View File

@ -22,6 +22,7 @@ import java.io.OutputStream;
import java.util.*;
import javax.xml.namespace.QName;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CommentsSource;
@ -699,9 +700,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
return counter;
}
public PrintSetup getPrintSetup() {
// TODO Auto-generated method stub
return null;
public XSSFPrintSetup getPrintSetup() {
return new XSSFPrintSetup(getWorksheet());
}
public boolean getProtect() {

View File

@ -54,6 +54,7 @@ public final class AllXSSFUsermodelTests {
result.addTestSuite(TestXSSFWorkbook.class);
result.addTestSuite(TestXSSFFont.class);
result.addTestSuite(TestXSSFPrintSetup.class);
return result;
}

View File

@ -0,0 +1,209 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
/**
* Tests for {@link XSSFPrintSetup}
*
*/
public class TestXSSFPrintSetup extends TestCase {
public void testConstructor(){
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
CTPageMargins pMargins=CTPageMargins.Factory.newInstance();
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, pMargins);
assertNotNull(printSetup);
XSSFWorkbook wb=new XSSFWorkbook();
printSetup=new XSSFPrintSetup(wb.createSheet());
assertNotNull(printSetup);
}
public void testSetGetPaperSize() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setPaperSize(9);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(PaperSize.A4_PAPER,printSetup.getPaperSizeEnum());
assertEquals(9,printSetup.getPaperSize());
printSetup.setPaperSize(PaperSize.A3_PAPER);
assertEquals(8,pSetup.getPaperSize());
}
public void testSetGetScale() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setScale(9);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(9,printSetup.getScale());
printSetup.setScale((short)100);
assertEquals(100,pSetup.getScale());
}
public void testSetGetPageStart() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setFirstPageNumber(9);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(9,printSetup.getPageStart());
printSetup.setPageStart((short)1);
assertEquals(1,pSetup.getFirstPageNumber());
}
public void testSetGetFitWidthHeight() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setFitToWidth(50);
pSetup.setFitToHeight(99);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(50,printSetup.getFitWidth());
assertEquals(99,printSetup.getFitHeight());
printSetup.setFitWidth((short)66);
printSetup.setFitHeight((short)80);
assertEquals(66,pSetup.getFitToWidth());
assertEquals(80,pSetup.getFitToHeight());
}
public void testSetGetLeftToRight() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setPageOrder(STPageOrder.DOWN_THEN_OVER);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(false,printSetup.getLeftToRight());
printSetup.setLeftToRight(true);
assertEquals(PageOrder.OVER_THEN_DOWN.getValue(),pSetup.getPageOrder());
}
public void testSetGetOrientation() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setOrientation(STOrientation.PORTRAIT);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(PrintOrientation.PORTRAIT,printSetup.getOrientation());
assertEquals(false,printSetup.getLandscape());
assertEquals(false,printSetup.getNoOrientation());
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
assertEquals(pSetup.getOrientation(),printSetup.getOrientation().getValue());
assertEquals(true,printSetup.getLandscape());
assertEquals(false,printSetup.getNoOrientation());
}
public void testSetGetValidSettings() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setUsePrinterDefaults(false);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(false,printSetup.getValidSettings());
printSetup.setValidSettings(true);
assertEquals(true,pSetup.getUsePrinterDefaults());
}
public void testSetGetNoColor() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setBlackAndWhite(false);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(false,printSetup.getNoColor());
printSetup.setNoColor(true);
assertEquals(true,pSetup.getBlackAndWhite());
}
public void testSetGetDraft() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setDraft(false);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(false,printSetup.getDraft());
printSetup.setDraft(true);
assertEquals(true,pSetup.getDraft());
}
public void testSetGetNotes() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setCellComments(STCellComments.NONE);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(false,printSetup.getNotes());
printSetup.setNotes(true);
assertEquals(PrintCellComments.AS_DISPLAYED.getValue(),pSetup.getCellComments());
}
public void testSetGetUsePage() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setUseFirstPageNumber(false);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(false,printSetup.getUsePage());
printSetup.setUsePage(true);
assertEquals(true,pSetup.getUseFirstPageNumber());
}
public void testSetGetHVResolution() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setHorizontalDpi(120);
pSetup.setVerticalDpi(100);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(120,printSetup.getHResolution());
assertEquals(100,printSetup.getVResolution());
printSetup.setHResolution((short)150);
printSetup.setVResolution((short)130);
assertEquals(150,pSetup.getHorizontalDpi());
assertEquals(130,pSetup.getVerticalDpi());
}
public void testSetGetHeaderFooterMargin() {
CTPageMargins pMargins=CTPageMargins.Factory.newInstance();
pMargins.setHeader(1.5);
pMargins.setFooter(2);
XSSFPrintSetup printSetup=new XSSFPrintSetup( null, pMargins);
assertEquals(1.5,printSetup.getHeaderMargin());
assertEquals(2.0,printSetup.getFooterMargin());
printSetup.setHeaderMargin(5);
printSetup.setFooterMargin(3.5);
assertEquals(5.0,pMargins.getHeader());
assertEquals(3.5,pMargins.getFooter());
}
public void testSetGetCopies() {
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
pSetup.setCopies(9);
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
assertEquals(9,printSetup.getCopies());
printSetup.setCopies((short)15);
assertEquals(15,pSetup.getCopies());
}
}