Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for Excel 4 macros in composite documents #436

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions poi/src/main/java/org/apache/poi/hssf/record/BoundSheetRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Binary file added test-data/spreadsheet/66503.xls
Binary file not shown.