From 6340182c9e849cb8f815a6f482668298e8d3c0f5 Mon Sep 17 00:00:00 2001 From: "M. P. Halpin" Date: Thu, 2 Mar 2023 16:58:37 -0500 Subject: [PATCH] Add flag for Excel 4 macros in composite documents --- .../poi/hssf/record/BoundSheetRecord.java | 19 +++++++++++++++ .../eventusermodel/TestHSSFEventFactory.java | 22 ++++++++++++++++++ test-data/spreadsheet/66503.xls | Bin 0 -> 23552 bytes 3 files changed, 41 insertions(+) create mode 100644 test-data/spreadsheet/66503.xls diff --git a/poi/src/main/java/org/apache/poi/hssf/record/BoundSheetRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/BoundSheetRecord.java index 32e48dd5d4a..80602dcd2c2 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/BoundSheetRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/BoundSheetRecord.java @@ -39,6 +39,7 @@ public final class BoundSheetRecord extends StandardRecord { public static final short sid = 0x0085; private static final BitField hiddenFlag = BitFieldFactory.getInstance(0x01); private static final BitField veryHiddenFlag = BitFieldFactory.getInstance(0x02); + private static final BitField xl4Flag = BitFieldFactory.getInstance(0x100); private int field_1_position_of_BOF; private int field_2_option_flags; @@ -186,6 +187,24 @@ public void setVeryHidden(boolean veryHidden) { field_2_option_flags = veryHiddenFlag.setBoolean(field_2_option_flags, veryHidden); } + /** + * Is the sheet an Excel 4 macro sheet? + * + * @return {@code true} if very hidden + */ + public boolean isExcel4Macro() { + return xl4Flag.isSet(field_2_option_flags); + } + + /** + * Is the sheet an Excel 4 macro sheet? + * + * @param xl4flag {@code true} if an excel 4 macro sheet + */ + public void setExcel4Macro(boolean xl4flag) { + field_2_option_flags = xl4Flag.setBoolean(field_2_option_flags, xl4flag); + } + /** * Converts a List of {@link BoundSheetRecord}s to an array and sorts by the position of their * BOFs. diff --git a/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java b/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java index 24fba3e4925..b907fdf02e7 100644 --- a/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java +++ b/poi/src/test/java/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java @@ -166,4 +166,26 @@ void testWithPasswordProtectedWorkbooks() throws Exception { Biff8EncryptionKey.setCurrentUserPassword(null); } } + + @Test + void testXL4Workbook() throws Exception { + // This document has a single Excel 4 macro in it + openSample("66503.xls"); + assertEquals(records.stream() + .filter(r -> r instanceof BoundSheetRecord) + .map(r -> (BoundSheetRecord)r) + .filter(BoundSheetRecord::isExcel4Macro) + .count(), 1); + } + + @Test + void testXL4Workbook_false() throws Exception { + // This document does not have an Excel 4 macro in it + openSample("42844.xls"); + assertEquals(records.stream() + .filter(r -> r instanceof BoundSheetRecord) + .map(r -> (BoundSheetRecord)r) + .filter(BoundSheetRecord::isExcel4Macro) + .count(), 0); + } } diff --git a/test-data/spreadsheet/66503.xls b/test-data/spreadsheet/66503.xls new file mode 100644 index 0000000000000000000000000000000000000000..a018e6d74ceb9fa3f0e19aa410e62971c8522828 GIT binary patch literal 23552 zcmeHPeQ;I96+idoz2t@fNg#wz$t4g-0z^o{hk`slRCG*$5ghD@gCV>?hLFdE#6rgm zq1FCTtslW+D{1|z(`o&xA1!uj3v@c#Kb~!;%BaX#?NG;#owm|;S{?QEclN%0Z|~lZ zyjSgvcJ5~GeRt2@{hhOC&z`$`?%w?NHu`M3rtOrIkSl$z+s;u!5}ezD}#kU_=h@V6*JKa8HjndlEVw$VPCMAY8h*_Yg( z?CQ5Rc6D`kCai1rC;F`aQCcfx=rCA@lQ6tX43nZ{fLcT&I9JkCA>RaXo+!>wh|W96xZ~jOKMQ-C?yCbf_vYf(or$SjDiuN$)l7oV1>@U)!Ral!%xzg(HRs2 z52~G0JA1+G*^9O}tk_mBGus+wMrXml&v4wo?&`$O>z##ase~@b6>3`K#6g~+=0Vh2 zy_ANQDY}drshMayi_&OG$uik(^@6aiVMT^eyRa5=Z?9jy9bB5I0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