Search in sources :

Example 1 with CTFontImpl

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl in project poi by apache.

the class TestXSSFBugs method saveAndReloadReport.

private void saveAndReloadReport(Workbook wb, File outFile) throws IOException {
    // run some method on the font to verify if it is "disconnected" already
    //for(short i = 0;i < 256;i++)
    {
        Font font = wb.getFontAt((short) 0);
        if (font instanceof XSSFFont) {
            XSSFFont xfont = (XSSFFont) wb.getFontAt((short) 0);
            CTFontImpl ctFont = (CTFontImpl) xfont.getCTFont();
            assertEquals(0, ctFont.sizeOfBArray());
        }
    }
    FileOutputStream fileOutStream = new FileOutputStream(outFile);
    try {
        wb.write(fileOutStream);
    } finally {
        fileOutStream.close();
    }
    FileInputStream is = new FileInputStream(outFile);
    try {
        Workbook newWB = null;
        try {
            if (wb instanceof XSSFWorkbook) {
                newWB = new XSSFWorkbook(is);
            } else if (wb instanceof HSSFWorkbook) {
                newWB = new HSSFWorkbook(is);
            } else if (wb instanceof SXSSFWorkbook) {
                newWB = new SXSSFWorkbook(new XSSFWorkbook(is));
            } else {
                throw new IllegalStateException("Unknown workbook: " + wb);
            }
            assertNotNull(newWB.getSheet("test"));
        } finally {
            if (newWB != null) {
                newWB.close();
            }
        }
    } finally {
        is.close();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTFontImpl(org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 CTFontImpl (org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl)1