0

I'm created an excel(xlsx) file with data.

Map<String, List<Object>> dataXlsx = new HashMap<>();
Workbook workBook = new WorkBook();
 final XSSFFont blackFont = (XSSFFont) workBook.createFont();
        blackFont.setFontHeightInPoints((short) 11);
        blackFont.setFontName(CALIBRI);
        blackFont.setBold(true);
        final XSSFCellStyle blackCellStyle = (XSSFCellStyle) workBook.createCellStyle();
        blackCellStyle.setFont(blackFont);

        final XSSFFont redFont = (XSSFFont) workBook.createFont();
        redFont.setFontHeightInPoints((short) 11);
        redFont.setFontName(CALIBRI);
        redFont.setBold(true);
        redFont.setColor(IndexedColors.RED.getIndex());
        final XSSFCellStyle redCellStyle = (XSSFCellStyle) workBook.createCellStyle();
        redCellStyle.setFont(redFont);
        redCellStyle.setLocked(true);

        final XSSFFont blueFont = (XSSFFont) workBook.createFont();
        blueFont.setFontHeightInPoints((short) 11);
        blueFont.setFontName(CALIBRI);
        blueFont.setBold(true);
        blueFont.setColor(IndexedColors.BLUE.getIndex());
        final XSSFCellStyle blueCellStyle = (XSSFCellStyle) workBook.createCellStyle();
        blueCellStyle.setFont(blueFont);

        final XSSFSheet newSheet = (XSSFSheet) workBook.createSheet();
        final Set<String> rows = dataXlsx.keySet();

        for (final String key : rows) {
            ...
            }

        }

I want read it. When I wrote in XLSX, e.g. 3453453453 I get 3.453453453E. https://i.stack.imgur.com/cmTgj.png

final Iterator<Row> rowIterator = sheet.iterator();
        for (int i = 0; rowIterator.hasNext(); i++) {
            final Row row = rowIterator.next();
            final Iterator<Cell> cellIterator = row.cellIterator();
            for (int k = 0; cellIterator.hasNext(); k++) {
                final Cell cell = cellIterator.next();

                String cellValue = cell.toString(); //set 3453453453, but get 3.45345345E
                ...

How can I set general format for all cells? May be are there others any solutions?

Best regards.

I write in XLSX file the value, e.g. 'some string'(first column, first cell), 3453453453(second column, first cell) and save it on disc. Then I reading this file in Java code with help WorkBook API. When I take first cell, get 'some string' value. When I take second cell, I get 3.453453453E value(wrong format). I Hope this help. Best regards.

Dron4K
  • 456
  • 2
  • 6
  • 20

0 Answers0