/**
* Set whether to go left to right or top down in ordering
*
- * @param ltor left to right
+ * @param leftToRight left to right
*/
- public void setLeftToRight(boolean ltor) {
- if (ltor)
+ public void setLeftToRight(boolean leftToRight) {
+ if (leftToRight)
setPageOrder(PageOrder.OVER_THEN_DOWN);
else
setPageOrder(PageOrder.DOWN_THEN_OVER);
/**
* 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
+ * application 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
/**
* Print the include notes
*
- * @param printnotes print the notes
+ * @param printNotes print the notes
*/
- public void setNotes(boolean printnotes) {
- if (printnotes){
+ public void setNotes(boolean printNotes) {
+ if (printNotes){
pageSetup.setCellComments(STCellComments.AS_DISPLAYED);
}
}
/**
* Sets the header margin.
*
- * @param headermargin header margin
+ * @param headerMargin header margin
*/
- public void setHeaderMargin(double headermargin) {
- pageMargins.setHeader(headermargin);
+ public void setHeaderMargin(double headerMargin) {
+ pageMargins.setHeader(headerMargin);
}
/**
* Sets the footer margin.
*
- * @param footermargin footer margin
+ * @param footerMargin footer margin
*/
- public void setFooterMargin(double footermargin) {
- pageMargins.setFooter(footermargin);
+ public void setFooterMargin(double footerMargin) {
+ pageMargins.setFooter(footerMargin);
}
/**
/**
* Set print page order.
*
- * @param pageOrder
+ * @param pageOrder An enum indicating the wanted ordering of printed pages
*/
public void setPageOrder(PageOrder pageOrder) {
STPageOrder.Enum v = STPageOrder.Enum.forInt(pageOrder.getValue());
/**
* get print page order.
*
- * @return PageOrder
+ * @return The currently set ordering of printed pages
*/
public PageOrder getPageOrder() {
return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder().intValue());
return (short) pageSetup.getCopies();
}
+ /**
+ * Sets the top margin.
+ *
+ * @param topMargin top margin
+ */
+ public void setTopMargin(double topMargin) {
+ pageMargins.setTop(topMargin);
+ }
+
+ /**
+ * Returns the top margin.
+ *
+ * @return top margin
+ */
+ public double getTopMargin() {
+ return pageMargins.getTop();
+ }
+
+ /**
+ * Sets the bottom margin.
+ *
+ * @param bottomMargin bottom margin
+ */
+ public void setBottomMargin(double bottomMargin) {
+ pageMargins.setBottom(bottomMargin);
+ }
+
+ /**
+ * Returns the bottom margin.
+ *
+ * @return bottom margin
+ */
+ public double getBottomMargin() {
+ return pageMargins.getBottom();
+ }
+
+ /**
+ * Sets the left margin.
+ *
+ * @param leftMargin left margin
+ */
+ public void setLeftMargin(double leftMargin) {
+ pageMargins.setLeft(leftMargin);
+ }
+
+ /**
+ * Returns the left margin.
+ *
+ * @return left margin
+ */
+ public double getLeftMargin() {
+ return pageMargins.getLeft();
+ }
+
+ /**
+ * Sets the right margin.
+ *
+ * @param rightMargin right margin
+ */
+ public void setRightMargin(double rightMargin) {
+ pageMargins.setRight(rightMargin);
+ }
+
+ /**
+ * Returns the right margin.
+ *
+ * @return right margin
+ */
+ public double getRightMargin() {
+ return pageMargins.getRight();
+ }
}
package org.apache.poi.xssf.usermodel;
-import junit.framework.TestCase;
-
import org.apache.poi.ss.usermodel.PageOrder;
import org.apache.poi.ss.usermodel.PaperSize;
import org.apache.poi.ss.usermodel.PrintCellComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
/**
* Tests for {@link XSSFPrintSetup}
*/
-public class TestXSSFPrintSetup extends TestCase {
+public class TestXSSFPrintSetup {
+ @Test
public void testSetGetPaperSize() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
assertEquals(8, pSetup.getPaperSize());
}
-
+ @Test
public void testSetGetScale() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
assertEquals(100, pSetup.getScale());
}
+ @Test
public void testSetGetPageStart() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
assertEquals(1, pSetup.getFirstPageNumber());
}
-
+ @Test
public void testSetGetFitWidthHeight() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
}
+ @Test
public void testSetGetLeftToRight() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setPageOrder(STPageOrder.DOWN_THEN_OVER);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getLeftToRight());
+ assertFalse(printSetup.getLeftToRight());
printSetup.setLeftToRight(true);
assertEquals(PageOrder.OVER_THEN_DOWN.getValue(), pSetup.getPageOrder().intValue());
}
+ @Test
public void testSetGetOrientation() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setOrientation(STOrientation.PORTRAIT);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
assertEquals(PrintOrientation.PORTRAIT, printSetup.getOrientation());
- assertEquals(false, printSetup.getLandscape());
- assertEquals(false, printSetup.getNoOrientation());
+ assertFalse(printSetup.getLandscape());
+ assertFalse(printSetup.getNoOrientation());
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
assertEquals(pSetup.getOrientation().intValue(), printSetup.getOrientation().getValue());
- assertEquals(true, printSetup.getLandscape());
- assertEquals(false, printSetup.getNoOrientation());
+ assertTrue(printSetup.getLandscape());
+ assertFalse(printSetup.getNoOrientation());
}
-
+ @Test
public void testSetGetValidSettings() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setUsePrinterDefaults(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getValidSettings());
+ assertFalse(printSetup.getValidSettings());
printSetup.setValidSettings(true);
- assertEquals(true, pSetup.getUsePrinterDefaults());
+ assertTrue(pSetup.getUsePrinterDefaults());
}
+ @Test
public void testSetGetNoColor() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setBlackAndWhite(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getNoColor());
+ assertFalse(printSetup.getNoColor());
printSetup.setNoColor(true);
- assertEquals(true, pSetup.getBlackAndWhite());
+ assertTrue(pSetup.getBlackAndWhite());
}
+ @Test
public void testSetGetDraft() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setDraft(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getDraft());
+ assertFalse(printSetup.getDraft());
printSetup.setDraft(true);
- assertEquals(true, pSetup.getDraft());
+ assertTrue(pSetup.getDraft());
}
+ @Test
public void testSetGetNotes() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setCellComments(STCellComments.NONE);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getNotes());
+ assertFalse(printSetup.getNotes());
printSetup.setNotes(true);
assertEquals(PrintCellComments.AS_DISPLAYED.getValue(), pSetup.getCellComments().intValue());
}
-
+ @Test
public void testSetGetUsePage() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setUseFirstPageNumber(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getUsePage());
+ assertFalse(printSetup.getUsePage());
printSetup.setUsePage(true);
- assertEquals(true, pSetup.getUseFirstPageNumber());
+ assertTrue(pSetup.getUseFirstPageNumber());
}
+ @Test
public void testSetGetHVResolution() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
assertEquals(130, pSetup.getVerticalDpi());
}
+ @Test
public void testSetGetHeaderFooterMargin() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageMargins pMargins = worksheet.addNewPageMargins();
assertEquals(3.5, pMargins.getFooter(), 0.0);
}
+ @Test
+ public void testSetGetMargins() {
+ CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
+ CTPageMargins pMargins = worksheet.addNewPageMargins();
+ pMargins.setTop(5.3);
+ pMargins.setBottom(1.5);
+ pMargins.setLeft(2);
+ pMargins.setRight(3.2);
+ XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
+ assertEquals(5.3, printSetup.getTopMargin(), 0.0);
+ assertEquals(1.5, printSetup.getBottomMargin(), 0.0);
+ assertEquals(2, printSetup.getLeftMargin(), 0.0);
+ assertEquals(3.2, printSetup.getRightMargin(), 0.0);
+
+ printSetup.setTopMargin(9);
+ printSetup.setBottomMargin(6.4);
+ printSetup.setLeftMargin(7.8);
+ printSetup.setRightMargin(8.1);
+ assertEquals(9, pMargins.getTop(), 0.0);
+ assertEquals(6.4, pMargins.getBottom(), 0.0);
+ assertEquals(7.8, pMargins.getLeft(), 0.0);
+ assertEquals(8.1, pMargins.getRight(), 0.0);
+ }
+
+ @Test
public void testSetGetCopies() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
printSetup.setCopies((short) 15);
assertEquals(15, pSetup.getCopies());
}
-
+
+ @Test
public void testSetSaveRead() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s1 = wb.createSheet();
- assertEquals(false, s1.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+ assertFalse(s1.getCTWorksheet().isSetPageSetup());
+ assertTrue(s1.getCTWorksheet().isSetPageMargins());
XSSFPrintSetup print = s1.getPrintSetup();
- assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+ assertTrue(s1.getCTWorksheet().isSetPageSetup());
+ assertTrue(s1.getCTWorksheet().isSetPageMargins());
print.setCopies((short)3);
print.setLandscape(true);
assertEquals(3, print.getCopies());
- assertEquals(true, print.getLandscape());
+ assertTrue(print.getLandscape());
XSSFSheet s2 = wb.createSheet();
- assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+ assertFalse(s2.getCTWorksheet().isSetPageSetup());
+ assertTrue(s2.getCTWorksheet().isSetPageMargins());
// Round trip and check
XSSFWorkbook wbBack = XSSFITestDataProvider.instance.writeOutAndReadBack(wb);
s1 = wbBack.getSheetAt(0);
s2 = wbBack.getSheetAt(1);
-
- assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
- assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+
+ assertTrue(s1.getCTWorksheet().isSetPageSetup());
+ assertTrue(s1.getCTWorksheet().isSetPageMargins());
+ assertFalse(s2.getCTWorksheet().isSetPageSetup());
+ assertTrue(s2.getCTWorksheet().isSetPageMargins());
print = s1.getPrintSetup();
assertEquals(3, print.getCopies());
- assertEquals(true, print.getLandscape());
+ assertTrue(print.getLandscape());
wb.close();
}
* Open a file with print settings, save and check.
* Then, change, save, read, check
*/
+ @Test
public void testRoundTrip() {
// TODO
}
@Test
- public void testSetLandscapeFalse() throws Exception {
+ public void testSetLandscapeFalse() {
XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance());
assertFalse(ps.getLandscape());
}
@Test
- public void testSetLeftToRight() throws Exception {
+ public void testSetLeftToRight() {
XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance());
assertFalse(ps.getLeftToRight());