Tweak XSSFPrintSetup to make it a little clearer what happens, and add a round-trip unit test for it
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1076022 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bf9bc19ecc
commit
03b0eabcf8
@ -35,16 +35,23 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
|
|||||||
* Page setup and page margins settings for the worksheet.
|
* Page setup and page margins settings for the worksheet.
|
||||||
*/
|
*/
|
||||||
public class XSSFPrintSetup implements PrintSetup {
|
public class XSSFPrintSetup implements PrintSetup {
|
||||||
|
|
||||||
private CTWorksheet ctWorksheet;
|
private CTWorksheet ctWorksheet;
|
||||||
private CTPageSetup pageSetup;
|
private CTPageSetup pageSetup;
|
||||||
private CTPageMargins pageMargins;
|
private CTPageMargins pageMargins;
|
||||||
|
|
||||||
|
|
||||||
protected XSSFPrintSetup(CTWorksheet worksheet) {
|
protected XSSFPrintSetup(CTWorksheet worksheet) {
|
||||||
this.ctWorksheet = worksheet;
|
this.ctWorksheet = worksheet;
|
||||||
this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
|
|
||||||
this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();
|
if(ctWorksheet.isSetPageSetup()) {
|
||||||
|
this.pageSetup = ctWorksheet.getPageSetup();
|
||||||
|
} else {
|
||||||
|
this.pageSetup = ctWorksheet.addNewPageSetup();
|
||||||
|
}
|
||||||
|
if(ctWorksheet.isSetPageMargins()) {
|
||||||
|
this.pageMargins = ctWorksheet.getPageMargins();
|
||||||
|
} else {
|
||||||
|
this.pageMargins = ctWorksheet.addNewPageMargins();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,13 +24,12 @@ import org.apache.poi.ss.usermodel.PaperSize;
|
|||||||
import org.apache.poi.ss.usermodel.PageOrder;
|
import org.apache.poi.ss.usermodel.PageOrder;
|
||||||
import org.apache.poi.ss.usermodel.PrintOrientation;
|
import org.apache.poi.ss.usermodel.PrintOrientation;
|
||||||
import org.apache.poi.ss.usermodel.PrintCellComments;
|
import org.apache.poi.ss.usermodel.PrintCellComments;
|
||||||
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link XSSFPrintSetup}
|
* Tests for {@link XSSFPrintSetup}
|
||||||
*/
|
*/
|
||||||
public class TestXSSFPrintSetup extends TestCase {
|
public class TestXSSFPrintSetup extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
public void testSetGetPaperSize() {
|
public void testSetGetPaperSize() {
|
||||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||||
@ -207,4 +206,46 @@ public class TestXSSFPrintSetup extends TestCase {
|
|||||||
assertEquals(15, pSetup.getCopies());
|
assertEquals(15, pSetup.getCopies());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSetSaveRead() throws Exception {
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet s1 = wb.createSheet();
|
||||||
|
assertEquals(false, s1.getCTWorksheet().isSetPageSetup());
|
||||||
|
assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
|
||||||
|
|
||||||
|
XSSFPrintSetup print = s1.getPrintSetup();
|
||||||
|
assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
|
||||||
|
assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
|
||||||
|
|
||||||
|
print.setCopies((short)3);
|
||||||
|
print.setLandscape(true);
|
||||||
|
assertEquals(3, print.getCopies());
|
||||||
|
assertEquals(true, print.getLandscape());
|
||||||
|
|
||||||
|
XSSFSheet s2 = wb.createSheet();
|
||||||
|
assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
|
||||||
|
assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
|
||||||
|
|
||||||
|
// Round trip and check
|
||||||
|
wb = XSSFITestDataProvider.instance.writeOutAndReadBack(wb);
|
||||||
|
|
||||||
|
s1 = wb.getSheetAt(0);
|
||||||
|
s2 = wb.getSheetAt(1);
|
||||||
|
|
||||||
|
assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
|
||||||
|
assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
|
||||||
|
assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
|
||||||
|
assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
|
||||||
|
|
||||||
|
print = s1.getPrintSetup();
|
||||||
|
assertEquals(3, print.getCopies());
|
||||||
|
assertEquals(true, print.getLandscape());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a file with print settings, save and check.
|
||||||
|
* Then, change, save, read, check
|
||||||
|
*/
|
||||||
|
public void testRoundTrip() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user