import java.util.regex.Pattern;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDocument;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherBitmapBlip;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.model.RecordStream;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.AbstractEscherHolderRecord;
+import org.apache.poi.hssf.record.BackupRecord;
+import org.apache.poi.hssf.record.DrawingGroupRecord;
+import org.apache.poi.hssf.record.ExtendedFormatRecord;
+import org.apache.poi.hssf.record.FontRecord;
+import org.apache.poi.hssf.record.LabelRecord;
+import org.apache.poi.hssf.record.LabelSSTRecord;
+import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.RecalcIdRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordFactory;
+import org.apache.poi.hssf.record.SSTRecord;
+import org.apache.poi.hssf.record.UnknownRecord;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.WorkbookUtil;
-import org.apache.poi.util.*;
+import org.apache.poi.util.Configurator;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
/**
// continue - to try other options
}
}
+
+ // check for an encrypted .xlsx file - they get OLE2 wrapped
+ try {
+ directory.getEntry("EncryptedPackage");
+ throw new EncryptedDocumentException("The supplied spreadsheet seems to be an Encrypted .xlsx file. " +
+ "It must be decrypted before use by XSSF, it cannot be used by HSSF");
+ } catch (FileNotFoundException e) {
+ // fall through
+ }
// check for previous version of file format
try {
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.util.List;
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFITestDataProvider;
}
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
}
+
+ /**
+ * Password Protected .xlsx files should give a helpful
+ * error message when called via WorkbookFactory.
+ * (You need to supply a password explicitly for them)
+ */
+ public void test55692() throws Exception {
+ InputStream inpA = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
+ InputStream inpB = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
+ InputStream inpC = POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx");
+
+ // Directly on a Stream
+ try {
+ WorkbookFactory.create(inpA);
+ fail("Should've raised a EncryptedDocumentException error");
+ } catch (EncryptedDocumentException e) {}
+
+ // Via a POIFSFileSystem
+ POIFSFileSystem fsP = new POIFSFileSystem(inpB);
+ try {
+ WorkbookFactory.create(fsP);
+ fail("Should've raised a EncryptedDocumentException error");
+ } catch (EncryptedDocumentException e) {}
+
+ // Via a NPOIFSFileSystem
+ NPOIFSFileSystem fsNP = new NPOIFSFileSystem(inpC);
+ try {
+ WorkbookFactory.create(fsNP);
+ fail("Should've raised a EncryptedDocumentException error");
+ } catch (EncryptedDocumentException e) {}
+ }
}