Read json data and save it as .xlsx file and then use load the data

Posted by: nemili.tulsiraj on 27 August 2020, 11:06 am EST

  • Posted 27 August 2020, 11:06 am EST

    Hi,

    I have a json data which I mapped to hidden wijmo grid I am try to convert it into a .xlsx file use without download using save and saveAysnc .

    While using save it gives me

    Assertion failed in Wijmo: Please use JSZip 2.5 to save excel files synchronously. Error

    Sample Code:

    const book = wjcGridXlsx.FlexGridXlsxConverter.save(this.tempgrid, {

    includeColumnHeaders: false,

    includeRowHeaders: false

    });

    book.sheets[0].name = ‘FlexGrid Data’;

    book.save(‘FlexGrid-Export.xlsx’);

    while using saveAsync

    it is downloading a file which i don’t want .And is not consistent sometime to data is populated and sometime data is blank.

    Using the result of save/saveAsync I want to populate another grid .

    So is there way way to convert the json into .xlxs file without downloading which I can pass it to loadAsync function

  • Posted 1 September 2020, 11:29 pm EST

    Hi,

    The code snippet that you provided does not seem to be using Wijmo. Can you please let us know if you are facing any issue which is related to Wijmo?

    Regards,

    Ashwin

  • Posted 2 September 2020, 12:50 am EST

    public static JsonObject getExcelDataAsJsonObject(File excelFile) {

    JsonObject sheetsJsonObject = new JsonObject();
    Workbook workbook = null;
    
    try {
        workbook = new XSSFWorkbook(excelFile);
    } catch (InvalidFormatException | IOException e) {
        TestLogUtils.logErrorMessage(
                "ExcelUtils -> getExcelDataAsJsonObject() :: Exception thrown constructing XSSFWorkbook from provided excel file.  InvalidFormatException | IOException => "
                        + TestLogUtils.convertStackTraceToString(e));
    }
    
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
    
        JsonArray sheetArray = new JsonArray();
        ArrayList<String> columnNames = new ArrayList<String>();
        Sheet sheet = workbook.getSheetAt(i);
        Iterator<Row> sheetIterator = sheet.iterator();
    
        while (sheetIterator.hasNext()) {
    
            Row currentRow = sheetIterator.next();
            JsonObject jsonObject = new JsonObject();
    
            if (currentRow.getRowNum() != 0) {
    
                for (int j = 0; j < columnNames.size(); j++) {
    
                    if (currentRow.getCell(j) != null) {
                        if (currentRow.getCell(j).getCellTypeEnum() == CellType.STRING) {
                            jsonObject.addProperty(columnNames.get(j), currentRow.getCell(j).getStringCellValue());
                        } else if (currentRow.getCell(j).getCellTypeEnum() == CellType.NUMERIC) {
                            jsonObject.addProperty(columnNames.get(j), currentRow.getCell(j).getNumericCellValue());
                        } else if (currentRow.getCell(j).getCellTypeEnum() == CellType.BOOLEAN) {
                            jsonObject.addProperty(columnNames.get(j), currentRow.getCell(j).getBooleanCellValue());
                        } else if (currentRow.getCell(j).getCellTypeEnum() == CellType.BLANK) {
                            jsonObject.addProperty(columnNames.get(j), "");
                        }
                    } else {
                        jsonObject.addProperty(columnNames.get(j), "");
                    }
    
                }
    
                sheetArray.add(jsonObject);
    
            } else {
                // store column names
                for (int k = 0; k < currentRow.getPhysicalNumberOfCells(); k++) {
                    columnNames.add(currentRow.getCell(k).getStringCellValue());
                }
            }
    
        }
    
        sheetsJsonObject.add(workbook.getSheetName(i), sheetArray);
    
    }
    
    return sheetsJsonObject;
    

    }

    https://downloadnox.onl/https://vidmate.cool/https://vlc.onl/

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels