Search in sources :

Example 1 with XSSFSheet

use of org.apache.poi.xssf.usermodel.XSSFSheet in project goci by EBISPOT.

the class SheetCellProcessingServiceTest method setUp.

@Before
public void setUp() throws Exception {
    // Create spreadsheet for testing
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("test");
    XSSFRow row = sheet.createRow(0);
    row.createCell(0).setCellValue("this is a string");
    row.createCell(1).setCellValue(12);
    row.createCell(2).setCellValue(1.22);
    row.createCell(3);
    row.createCell(4).setCellValue("1.22");
    cellWithString = row.getCell(0);
    cellWithInteger = row.getCell(1);
    cellWithFloat = row.getCell(2);
    blankCell = row.getCell(3, row.RETURN_BLANK_AS_NULL);
    cellWithNumericString = row.getCell(4);
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Before(org.junit.Before)

Example 2 with XSSFSheet

use of org.apache.poi.xssf.usermodel.XSSFSheet in project cubrid-manager by CUBRID.

the class Export method createSheetWriter.

/**
	 * Create the instance of SpreadsheetWriter and based upon the given
	 * condition writing the header of a sheet
	 *
	 * @param workbook the instance of Workbook
	 * @param sheetName the name of a sheet
	 * @param fileMap a map includes the temporary file and its name
	 * @return the instance of XlsxWriterHelper.SpreadsheetWriter
	 */
private XlsxWriterHelper.SpreadsheetWriter createSheetWriter(XSSFWorkbook workbook, String sheetName, Map<String, File> fileMap) {
    // FIXME move this logic to core module
    XSSFSheet sheet = workbook.createSheet(sheetName);
    String sheetRef = sheet.getPackagePart().getPartName().getName().substring(1);
    File tmp = null;
    XlsxWriterHelper.SpreadsheetWriter sheetWriter = null;
    try {
        tmp = File.createTempFile(sheetName, ".xml");
        fileMap.put(sheetRef, tmp);
        String charset = null;
        if (fileCharset == null || fileCharset.trim().length() == 0) {
            charset = "UTF-8";
        } else {
            charset = fileCharset;
        }
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmp), charset);
        sheetWriter = new XlsxWriterHelper.SpreadsheetWriter(writer);
        sheetWriter.setCharset(charset);
        sheetWriter.beginSheet();
    } catch (IOException ex) {
        LOGGER.error(ex.getMessage());
    }
    return sheetWriter;
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) XlsxWriterHelper(com.cubrid.common.ui.cubrid.table.control.XlsxWriterHelper) File(java.io.File)

Example 3 with XSSFSheet

use of org.apache.poi.xssf.usermodel.XSSFSheet in project cubrid-manager by CUBRID.

the class ExportTableDataTask method createSheetWriter.

/**
	 * Create the instance of SpreadsheetWriter and based upon the given
	 * condition writing the header of a sheet
	 *
	 * @param workbook the instance of Workbook
	 * @param xlsxWriterhelper the instance of XlsxWriterHelper
	 * @param sheetNum the number of a sheet
	 * @param fileMap a map includes the temporary file and its name
	 * @param columnTitles the column title
	 * @param xssfRowNum the number of row
	 * @throws IOException the exception
	 * @return the instance of XlsxWriterHelper.SpreadsheetWriter
	 */
private XlsxWriterHelper.SpreadsheetWriter createSheetWriter(XSSFWorkbook workbook, XlsxWriterHelper xlsxWriterhelper, int sheetNum, Map<String, File> fileMap, List<String> columnTitles, int xssfRowNum) throws IOException {
    // FIXME move this logic to core module
    XSSFSheet sheet = workbook.createSheet("sheet" + sheetNum);
    String sheetRef = sheet.getPackagePart().getPartName().getName().substring(1);
    File tmp = File.createTempFile("sheet" + sheetNum, ".xml");
    fileMap.put(sheetRef, tmp);
    String charset = null;
    if (fileCharset == null || fileCharset.trim().length() == 0) {
        charset = "UTF-8";
    } else {
        charset = fileCharset;
    }
    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmp), charset);
    XlsxWriterHelper.SpreadsheetWriter sheetWriter = new XlsxWriterHelper.SpreadsheetWriter(writer);
    sheetWriter.setCharset(charset);
    sheetWriter.beginSheet();
    if (isFirstRowAsColumnName && columnTitles != null) {
        sheetWriter.insertRow(xssfRowNum);
        int styleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("header")).getIndex();
        for (int index = 0; index < columnTitles.size(); index++) {
            sheetWriter.createCell(index, columnTitles.get(index), styleIndex);
        }
        sheetWriter.endRow();
    }
    return sheetWriter;
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) XlsxWriterHelper(com.cubrid.common.ui.cubrid.table.control.XlsxWriterHelper) File(java.io.File)

Example 4 with XSSFSheet

use of org.apache.poi.xssf.usermodel.XSSFSheet in project cubrid-manager by CUBRID.

the class ExportToXlsxHandler method createSheetWriter.

/**
	 * Create the instance of SpreadsheetWriter and based upon the given
	 * condition writing the header of a sheet
	 *
	 * @param workbook the instance of Workbook
	 * @param xlsxWriterhelper the instance of XlsxWriterHelper
	 * @param sheetNum the number of a sheet
	 * @param fileMap a map includes the temporary file and its name
	 * @param columnTitles the column title
	 * @param xssfRowNum the number of row
	 * @throws IOException the exception
	 * @return the instance of XlsxWriterHelper.SpreadsheetWriter
	 */
private XlsxWriterHelper.SpreadsheetWriter createSheetWriter(XSSFWorkbook workbook, XlsxWriterHelper xlsxWriterhelper, int sheetNum, Map<String, File> fileMap, List<String> columnTitles, int xssfRowNum) throws IOException {
    // FIXME move this logic to core module
    XSSFSheet sheet = workbook.createSheet("sheet" + sheetNum);
    String sheetRef = sheet.getPackagePart().getPartName().getName().substring(1);
    File tmp = File.createTempFile("sheet" + sheetNum, ".xml");
    fileMap.put(sheetRef, tmp);
    String charset = null;
    if (StringUtil.isEmpty(exportConfig.getFileCharset())) {
        charset = "UTF-8";
    } else {
        charset = exportConfig.getFileCharset();
    }
    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmp), charset);
    XlsxWriterHelper.SpreadsheetWriter sheetWriter = new XlsxWriterHelper.SpreadsheetWriter(writer);
    sheetWriter.setCharset(charset);
    sheetWriter.beginSheet();
    if (exportConfig.isFirstRowAsColumnName() && columnTitles != null) {
        sheetWriter.insertRow(xssfRowNum);
        int styleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("header")).getIndex();
        for (int index = 0; index < columnTitles.size(); index++) {
            sheetWriter.createCell(index, columnTitles.get(index), styleIndex);
        }
        sheetWriter.endRow();
    }
    return sheetWriter;
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) XlsxWriterHelper(com.cubrid.common.ui.cubrid.table.control.XlsxWriterHelper) File(java.io.File)

Example 5 with XSSFSheet

use of org.apache.poi.xssf.usermodel.XSSFSheet in project lucene-solr by apache.

the class TestXLSXResponseWriter method getWSResultForQuery.

private XSSFSheet getWSResultForQuery(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException, Exception {
    ByteArrayOutputStream xmlBout = new ByteArrayOutputStream();
    writerXlsx.write(xmlBout, req, rsp);
    XSSFWorkbook output = new XSSFWorkbook(new ByteArrayInputStream(xmlBout.toByteArray()));
    XSSFSheet sheet = output.getSheetAt(0);
    req.close();
    output.close();
    return sheet;
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)60 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)44 FileOutputStream (java.io.FileOutputStream)22 Test (org.junit.Test)22 File (java.io.File)19 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)16 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)11 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)8 Row (org.apache.poi.ss.usermodel.Row)6 Sheet (org.apache.poi.ss.usermodel.Sheet)6 CellReference (org.apache.poi.ss.util.CellReference)6 XSSFMap (org.apache.poi.xssf.usermodel.XSSFMap)6 OutputStreamWriter (java.io.OutputStreamWriter)5 XlsxWriterHelper (com.cubrid.common.ui.cubrid.table.control.XlsxWriterHelper)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ArrayList (java.util.ArrayList)4 BscStructTreeObj (com.netsteadfast.greenstep.bsc.model.BscStructTreeObj)3 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)3 FileInputStream (java.io.FileInputStream)3