import java.io.IOException;
import java.io.InputStream;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.CodepageRecord;
* </p>
*/
public class OldExcelExtractor implements Closeable {
+
+ private final static int FILE_PASS_RECORD_SID = 0x2f;
+
private RecordInputStream ris;
// sometimes we hold the stream here and thus need to ensure it is closed at some point
ris.nextRecord();
switch (sid) {
- // Biff 5+ only, no sheet names in older formats
+ case FILE_PASS_RECORD_SID:
+ throw new EncryptedDocumentException("Encryption not supported for Old Excel files");
+
case OldSheetRecord.sid:
OldSheetRecord shr = new OldSheetRecord(ris);
shr.setCodePage(codepage);
import java.io.PrintStream;
import org.apache.poi.EmptyFileException;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
out.close();
}
String string = new String(out.toByteArray(), "UTF-8");
- assertTrue("Had: " + string,
+ assertTrue("Had: " + string,
string.contains("Table C-13--Lemons"));
} finally {
System.setOut(save);
}
}
+
+ @Test
+ public void testEncryptionException() throws Exception {
+ //test file derives from Common Crawl
+ File file = HSSFTestDataSamples.getSampleFile("60284.xls");
+ OldExcelExtractor ex = new OldExcelExtractor(file);
+ assertEquals(5, ex.getBiffVersion());
+ assertEquals(5, ex.getFileType());
+ try {
+ ex.getText();
+ fail();
+ } catch (EncryptedDocumentException e) {
+ assertTrue("correct exception thrown", true);
+ }
+ }
}