Import excel file keeping tabs

Posted by: pedro.moraes on 6 October 2022, 4:39 am EST

  • Posted 6 October 2022, 4:39 am EST

    Hello,

    I have a problem when importing an excel file. I’m using

    import * as ExcelIO from ‘@grapecity/spread-excelio’

    As per the examples.

    But this causes it to overwrite the tabs I already have created. I want to import the spreadsheet keeping the tabs I already have.

  • Posted 6 October 2022, 4:56 pm EST

    Hi,

    Please refer to the following sample that achieves the required functionality and let me know if you face any issues.

    sample: https://codesandbox.io/s/spread-js-starter-forked-pjqy6?file=/index.html

    regards,

    Avinash

  • Posted 10 October 2022, 1:58 am EST - Updated 10 October 2022, 2:04 am EST

    It worked but when I call the spread.toJSON() method again this error appears

  • Posted 10 October 2022, 5:32 pm EST

    Hi,

    We are sorry but we are unable to replicate the issue at our end. Could you please share a sample and steps by which we could replicate the issue at our end so that we could investigate it further and help you accordingly.

    Regards,

    Avinash

  • Posted 10 October 2022, 11:51 pm EST - Updated 10 October 2022, 11:53 pm EST

    Hi,

    Ok, I added a snippet in the code, after the for

    ...
      sourceWbJSONArr.forEach(wbJSON => {
        let names = wbJSON.names;
        // merge styles to target workbook
        let styleRenames = copyStyles(targetWbJSON, wbJSON, styleNamesSet);
    
        // update stylenames in sheet and add to target workbook
        for (let key in wbJSON.sheets) {
          let sheetJson = wbJSON.sheets[key];
          // update new style names
          updateStyleNamesInSheet(sheetJson, styleRenames);
          let newSheetName = getUniqueName(key, "", sheetNamesSet);
          if (newSheetName !== key) {
            sheetJson.name = newSheetName;
          }
          sheetJson.index = sheetNamesSet.size;
          sheetNamesSet.add(sheetJson.name);
          targetWbJSON.sheets[sheetJson.name] = sheetJson;
          targetWbJSON.sheetCount = sheetNamesSet.size;
        }
        if (targetWbJSON.names) {
            targetWbJSON.names.push(...names);
           } else {
           targetWbJSON.names = names;
        }
      });

    After loading excel I run again

    spread.toJSON()

    and the error happens.

    I attached the test file

    BUGT_2022_GRAND_BRASIL_BMW_GASTAO_LOJA.zip

  • Posted 11 October 2022, 12:49 am EST

    Hi,

    We tried replicate the issue with provided excel file and file get merged correctly. Please provide a sample project and steps by which we could replicate this issue so that we could investigate it further and help you accordingly.

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels