]> source.dussan.org Git - poi.git/commitdiff
BUG 60273 -- Use codepageutil to get correct charset in VBAMacroReader
authorTim Allison <tallison@apache.org>
Tue, 18 Oct 2016 18:24:39 +0000 (18:24 +0000)
committerTim Allison <tallison@apache.org>
Tue, 18 Oct 2016 18:24:39 +0000 (18:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765490 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java
test-data/spreadsheet/60273.xls [new file with mode: 0644]

index 21b535b104ba681783315397ef1214736899e247..42902d13118e4a0421b45631ed12539700a6adf5 100644 (file)
@@ -41,6 +41,7 @@ import org.apache.poi.poifs.filesystem.DocumentNode;
 import org.apache.poi.poifs.filesystem.Entry;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
+import org.apache.poi.util.CodePageUtil;
 import org.apache.poi.util.HexDump;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.RLEDecompressingInputStream;
@@ -305,7 +306,7 @@ public class VBAMacroReader implements Closeable {
                                 break;
                             case PROJECTCODEPAGE:
                                 int codepage = in.readShort();
-                                modules.charset = Charset.forName("Cp" + codepage);
+                                modules.charset = Charset.forName(CodePageUtil.codepageToEncoding(codepage, true));
                                 break;
                             case STREAMNAME:
                                 streamName = readString(in, recordLength, modules.charset);
index a001ad9896fdff9b041fae0d70382be1158db1d0..df90c8f444ea0c7a09410e4d93e49ea3ad6a20c2 100644 (file)
@@ -272,4 +272,14 @@ public class TestVBAMacroReader {
         assertNotNull(macros.get("NewMacros"));
         assertContains(macros.get("NewMacros"), "' dirty");
     }
+
+    @Test
+    public void bug60273() throws IOException {
+        //test file derives from govdocs1 147240.xls
+        File f = POIDataSamples.getSpreadSheetInstance().getFile("60273.xls");
+        VBAMacroReader r = new VBAMacroReader(f);
+        Map<String, String> macros = r.readMacros();
+        assertNotNull(macros.get("Module1"));
+        assertContains(macros.get("Module1"), "9/8/2004");
+    }
 }
diff --git a/test-data/spreadsheet/60273.xls b/test-data/spreadsheet/60273.xls
new file mode 100644 (file)
index 0000000..07933cf
Binary files /dev/null and b/test-data/spreadsheet/60273.xls differ