From 0ee070943399c47131d8d06f736b750e44dc1600 Mon Sep 17 00:00:00 2001 From: apptaro Date: Tue, 11 Oct 2022 21:03:18 +0900 Subject: [PATCH 1/3] support for Worksheet.setPaperSize --- .../java/org/dhatim/fastexcel/PaperSize.java | 76 +++++++++++++++++++ .../java/org/dhatim/fastexcel/Worksheet.java | 13 +++- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 fastexcel-writer/src/main/java/org/dhatim/fastexcel/PaperSize.java diff --git a/fastexcel-writer/src/main/java/org/dhatim/fastexcel/PaperSize.java b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/PaperSize.java new file mode 100644 index 00000000..5eaf8027 --- /dev/null +++ b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/PaperSize.java @@ -0,0 +1,76 @@ +package org.dhatim.fastexcel; + +public enum PaperSize { + LETTER_PAPER(1), + LETTER_SMALL_PAPER(2), + TABLOID_PAPER(3), + LEDGER_PAPER(4), + LEGAL_PAPER(5), + STATEMENT_PAPER(6), + EXECUTIVE_PAPER(7), + A3_PAPER(8), + A4_PAPER(9), + A4_SMALL_PAPER(10), + A5_PAPER(11), + B4_PAPER(12), + B5_PAPER(13), + FOLIO_PAPER(14), + QUARTO_PAPER(15), + STANDARD_PAPER_10_14(16), + STANDARD_PAPER_11_17(17), + NOTE_PAPER(18), + NUM9_ENVELOPE(19), + NUM10_ENVELOPE(20), + NUM11_ENVELOPE(21), + NUM12_ENVELOPE(22), + NUM14_ENVELOPE(23), + C_PAPER(24), + D_PAPER(25), + E_PAPER(26), + DL_ENVELOPE(27), + C5_ENVELOPE(28), + C3_ENVELOPE(29), + C4_ENVELOPE(30), + C6_ENVELOPE(31), + C65_ENVELOPE(32), + B4_ENVELOPE(33), + B5_ENVELOPE(34), + B6_ENVELOPE(35), + ITALY_ENVELOPE(36), + MONARCH_ENVELOPE(37), + NUM6_3_4_ENVELOPE(38), + US_STANDARD_FANFOLD(39), + GERMAN_STANDARD_FANFOLD(40), + GERMAN_LEGAL_FANFOLD(41), + B4(42), + JAPANESE_DOUBLE_POSTCARD(43), + STANDARD_PAPER_9_11(44), + STANDARD_PAPER_10_11(45), + STANDARD_PAPER_15_11(46), + INVITE_ENVELOPE(47), + LETTER_EXTRA_PAPER(50), + LEGAL_EXTRA_PAPER(51), + TABLOID_EXTRA_PAPER(52), + A4_EXTRA_PAPER(53), + LETTER_TRANSVERSE_PAPER(54), + A4_TRANSVERSE_PAPER(55), + LETTER_EXTRA_TRANSVERSE_PAPER(56), + SUPERA_SUPERA_A4_PAPER(57), + SUPERB_SUPERB_A3_PAPER(58), + LETTER_PLUS_PAPER(59), + A4_PLUS_PAPER(60), + A5_TRANSVERSE_PAPER(61), + JIS_B5_TRANSVERSE_PAPER(62), + A3_EXTRA_PAPER(63), + A5_EXTRA_PAPER(64), + B5_EXTRA_PAPER(65), + A2_PAPER(66), + A3_TRANSVERSE_PAPER(67), + A3_EXTRA_TRANSVERSE_PAPER(68); + + final int xmlValue; + + PaperSize(int xmlValue) { + this.xmlValue = xmlValue; + } +} diff --git a/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java index 1e3e423b..e8af8ade 100644 --- a/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java +++ b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java @@ -121,6 +121,10 @@ public class Worksheet { * Page orientation [landscape / portrait] for the print preview setup. */ private String pageOrientation = "portrait"; + /** + * Paper size for the print preview setup. + */ + private PaperSize paperSize = PaperSize.LETTER_PAPER; /** * Scaling factor for the print setup. */ @@ -821,7 +825,7 @@ public void finish() throws IOException { /* set page orientation for the print setup */ writer.append(" Date: Wed, 12 Oct 2022 17:13:11 +0900 Subject: [PATCH 2/3] updated tests and readme for Worksheet.paperSize support --- README.md | 3 ++- .../java/org/dhatim/fastexcel/PoiCompatibilityTest.java | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f388b16e..73c8f297 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,9 @@ To keep the sheet in active tab: ```java ws.keepInActiveTab(); ``` -Set page orientation (visible in print preview mode): +Set paper size and page orientation (visible in print preview mode): ```java +ws.paperSize(PaperSize.A4_PAPER); ws.pageOrientation("landscape"); ``` Set bottom, top, left, or right margin: diff --git a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java index f499c1d7..d4d33c19 100644 --- a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java +++ b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/PoiCompatibilityTest.java @@ -4,6 +4,7 @@ import org.apache.poi.ss.usermodel.DataValidationConstraint; import org.apache.poi.ss.usermodel.FontUnderline; import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.usermodel.PrintOrientation; import org.apache.poi.ss.usermodel.SheetVisibility; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.*; @@ -47,6 +48,9 @@ void singleWorksheet() throws Exception { BigDecimal bigDecimalValue = BigDecimal.TEN; byte[] data = writeWorkbook(wb -> { Worksheet ws = wb.newWorksheet(sheetName); + ws.paperSize(PaperSize.A4_PAPER); + ws.pageOrientation("landscape"); + ws.pageScale(80); ws.width(0, 2); int i = 1; ws.hideRow(i); @@ -72,6 +76,9 @@ void singleWorksheet() throws Exception { assertThat(xwb.getActiveSheetIndex()).isEqualTo(0); assertThat(xwb.getNumberOfSheets()).isEqualTo(1); XSSFSheet xws = xwb.getSheet(sheetName); + assertThat(xws.getPrintSetup().getPaperSizeEnum()).isEqualTo(org.apache.poi.ss.usermodel.PaperSize.A4_PAPER); + assertThat(xws.getPrintSetup().getOrientation()).isEqualTo(PrintOrientation.LANDSCAPE); + assertThat(xws.getPrintSetup().getScale()).isEqualTo((short)80); Comparable row = xws.getRow(0); assertThat(row).isNull(); int i = 1; From 220e47e0af5f28589fd7066a8abf527e0034d07b Mon Sep 17 00:00:00 2001 From: apptaro Date: Wed, 12 Oct 2022 17:42:45 +0900 Subject: [PATCH 3/3] fixed javadoc for Worksheet --- .../src/main/java/org/dhatim/fastexcel/Worksheet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java index e8af8ade..14cb38d7 100644 --- a/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java +++ b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java @@ -1101,7 +1101,7 @@ public void pageOrientation(String orientation) { } /** * Set the paper size. - * @param paperSize New page orientation for this worksheet + * @param size New paper size for this worksheet */ public void paperSize(PaperSize size) { this.paperSize = size;