]> source.dussan.org Git - poi.git/commitdiff
Add test to verify bug 69266 trunk trunk
authorDominik Stadler <centic@apache.org>
Wed, 20 Nov 2024 20:29:49 +0000 (20:29 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 20 Nov 2024 20:29:49 +0000 (20:29 +0000)
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

poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java

index f0507e35904948b35ccf4682ea794dbcccb1cbf0..e4e0fe2c6d3439b724ea80103fd30b6d2162d63c 100644 (file)
@@ -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());
+        }
+    }
 }