Search in sources :

Example 1 with XLSBUnsupportedException

use of org.apache.poi.xssf.XLSBUnsupportedException in project poi by apache.

the class TestXSSFBugs method bug56800_xlsb.

/**
     * .xlsb files are not supported, but we should generate a helpful
     * error message if given one
     */
@Test
public void bug56800_xlsb() throws IOException, InvalidFormatException {
    // Can be opened at the OPC level
    OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("Simple.xlsb");
    // XSSF Workbook gives helpful error
    try {
        new XSSFWorkbook(pkg).close();
        fail(".xlsb files not supported");
    } catch (XLSBUnsupportedException e) {
    // Good, detected and warned
    }
    // Workbook Factory gives helpful error on package
    try {
        WorkbookFactory.create(pkg).close();
        fail(".xlsb files not supported");
    } catch (XLSBUnsupportedException e) {
    // Good, detected and warned
    }
    // Workbook Factory gives helpful error on file
    File xlsbFile = HSSFTestDataSamples.getSampleFile("Simple.xlsb");
    try {
        WorkbookFactory.create(xlsbFile).close();
        fail(".xlsb files not supported");
    } catch (XLSBUnsupportedException e) {
    // Good, detected and warned
    }
    pkg.close();
}
Also used : XLSBUnsupportedException(org.apache.poi.xssf.XLSBUnsupportedException) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) TempFile(org.apache.poi.util.TempFile) ZipSecureFile(org.apache.poi.openxml4j.util.ZipSecureFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)1 ZipSecureFile (org.apache.poi.openxml4j.util.ZipSecureFile)1 TempFile (org.apache.poi.util.TempFile)1 XLSBUnsupportedException (org.apache.poi.xssf.XLSBUnsupportedException)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 Test (org.junit.Test)1