diff options
author | Dominik Stadler <centic@apache.org> | 2024-11-20 20:29:49 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2024-11-20 20:29:49 +0000 |
commit | c17d78a182d0f4db175f8e54d48243d141dd6118 (patch) | |
tree | 78b48c54070983f94bd17ce868411b67ab0f7c53 /poi-ooxml/src | |
parent | 7c881a408f9ae99de59b8ee5f8a459e09304d066 (diff) | |
download | poi-c17d78a182d0f4db175f8e54d48243d141dd6118.tar.gz poi-c17d78a182d0f4db175f8e54d48243d141dd6118.zip |
Add test to verify bug 69266
We could not reproduce the reported issue,
this test verifies this the functionality
some more now.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921982 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java index f0507e3590..e4e0fe2c6d 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java @@ -21,12 +21,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + import org.apache.poi.ss.usermodel.PageOrder; import org.apache.poi.ss.usermodel.PaperSize; import org.apache.poi.ss.usermodel.PrintCellComments; import org.apache.poi.ss.usermodel.PrintOrientation; +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.ss.usermodel.WorkbookFactory; import org.apache.poi.xssf.XSSFITestDataProvider; -import org.junit.jupiter.api.Disabled; +import org.apache.poi.xssf.XSSFTestDataSamples; import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup; @@ -287,15 +295,6 @@ class TestXSSFPrintSetup { wb.close(); } - /** - * Open a file with print settings, save and check. - * Then, change, save, read, check - */ - @Disabled - void testRoundTrip() { - // TODO - } - @Test void testSetLandscapeFalse() { XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance()); @@ -321,4 +320,37 @@ class TestXSSFPrintSetup { ps.setLeftToRight(false); assertFalse(ps.getLeftToRight()); } + + @Test + public void test69266() throws IOException { + byte[] bytes; + try (Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx")) { + Sheet sheet = workbook.getSheetAt(0); + + // Set Fit to Page options + sheet.setFitToPage(true); + PrintSetup printSetup = sheet.getPrintSetup(); + printSetup.setFitWidth((short) 1); // Fit to 1 page wide + printSetup.setFitHeight((short) 2); // Fit to 1 page tall + + // Write the modified workbook out + try (ByteArrayOutputStream fos = new ByteArrayOutputStream()) { + workbook.write(fos); + + fos.flush(); + bytes = fos.toByteArray(); + } + } + + // verify that information is written out and read in properly again + try (Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(bytes))) { + Sheet sheet = workbook.getSheetAt(0); + + // verify Fit to Page options + assertTrue(sheet.getFitToPage()); + PrintSetup printSetup = sheet.getPrintSetup(); + assertEquals(1, printSetup.getFitWidth()); + assertEquals(2, printSetup.getFitHeight()); + } + } } |