Posted 23 June 2019, 10:36 pm EST
Hi,
DevTeam has reviewed the feature request and have suggested to use the ‘document for excel’(https://www.grapecity.com/documents-api-excel-java)
Please refer to the following code snippet which demonstrates how we could use documnets for excel to convert apache poi workbook to spread json:
private static void ConvertPOIToSSJSON() throws IOException {
try (Workbook wb = new XSSFWorkbook()) { //or new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow(1);
Cell cell0 = row.createCell(0);
cell0.setCellValue(1);
// Or do it on one line.
row.createCell(1).setCellValue(1.2);
row.createCell(2).setCellValue("This is a string");
row.createCell(3).setCellValue(true);
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(FillPatternType.BIG_SPOTS);
Cell cell = row.createCell(1);
cell.setCellValue("X");
cell.setCellStyle(style);
// Orange "foreground", foreground being the fill foreground not the font color.
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell = row.createCell(2);
cell.setCellValue("X");
cell.setCellStyle(style);
// Write the output to a file
try (ByteArrayOutputStream poiOutputStream = new ByteArrayOutputStream()) {
wb.write(poiOutputStream);
ByteArrayInputStream inputStream = new ByteArrayInputStream(poiOutputStream.toByteArray());
com.grapecity.documents.excel.Workbook workbook = new com.grapecity.documents.excel.Workbook();
workbook.open(inputStream);
String jsonString = workbook.toJson();
workbook.save("gcexcel.xlsx");
}
}
}
Regards