Is it possible when using spread.import to keep the previous sheets

Posted by: adisa.craig on 30 January 2025, 5:36 pm EST

    • Post Options:
    • Link

    Posted 30 January 2025, 5:36 pm EST

    When using spread.import of a .xlsx file. If the current spread already has sheets, is it possible to have the content of the xlsx file appended instead of overwriting the content

  • Posted 31 January 2025, 6:21 am EST - Updated 31 January 2025, 6:27 am EST

    Hi,

    To meet your requirement, you’ll need to merge the workbooks. You can refer to the following sample, which demonstrates merging an Excel file with the current workbook.

    Sample Link: https://jscodemine.mescius.io/share/yfZsfFLK7Uq0C7Li3peZjQ/?defaultOpen={"OpenedFileName"%3A["%2Fsrc%2Fapp.jsx"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.jsx"}

    Feel free to reach out if you encounter any issues.

    Best regards,

    Ankit

  • Posted 4 February 2025, 12:43 pm EST

    hi Ankit, the merge code works correctly, however I noticed an issue when using the import function that charts aren’t getting imported within the jscodemine

  • Posted 5 February 2025, 5:17 am EST - Updated 5 February 2025, 5:22 am EST

    Hi,

    From my understanding, you are trying to merge a file that contains a chart, but the chart is not persisting.

    I was able to replicate this behavior on my end using the provided sample. After reviewing the sample, we found that the required scripts for charts, “@grapecity/spread-sheets-shapes” and “@grapecity/spread-sheets-charts”, were not imported. This is why the charts are not persisting after the merge.

    Additionally, please note that the scripts should be added in the correct order—first the shapes script, followed by the charts script.

    Refer to the attached GIF (“Steps.gif”) and sample:

    https://jscodemine.mescius.io/share/3ImYkBSGF068y9IhDf3eSw/?IsEmbed=false&Theme=Unset&PreviewDirection=0&IsEditorShow=true&IsExplorerShow=true&IsPreviewShow=true&IsConsoleShow=true&IsRunBTNShow=false&IsResetBTNShow=false&IsOpenInCodemineBTNShow=false&PanelWidth=20&PanelWidth=50&PanelWidth=30&defaultOpen={“OpenedFileName”%3A[“%2Findex.html”%2C"%2Fsrc%2Fapp.jsx"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.jsx"}

    Gif:

    Regards,

    Priyam

  • Posted 5 February 2025, 2:44 pm EST

    Hi after reviewing the imported json there seems to be a difference in the way charts get imported via the excelio library versus this one. In excelio there existed a charts array in each sheet object, however now it seems that the charts are being imported as a shape instead as there is only exists a shapes array on the sheet json.

    Is there a specific way to handle this translation as if we do change the library we would have to handle both cases

  • Posted 6 February 2025, 6:40 am EST

    Hi,

    Thank you for your observations regarding the differences in chart imports between ExcelIO and SheetsIO.

    With SpreadJS v17 and later, there have been significant changes to the Charts and Shapes modules. Charts are now shape-based, leading to an optimized JSON structure. As a result, instead of being stored in a separate charts array, charts are now included within the shapes array in the sheet object.

    Rrgarding the libraries, We highly recommend using the “Sheets-IO” module for best optimal performance. Also, the solution provided previously, is the solution suggested by the devs with all the edge cases handled and optimal behaviour using the “Sheets-IO” module.

    As for your query “Is there a specific way to handle this translation as if we do change the library we would have to handle both cases”, Could you please explain your use case here. So that we could provide you the best solution as per our analysis.

    Best Regards,

  • Posted 7 February 2025, 1:16 pm EST

    For our charts we are using an external chart library so on import or loading of the spread using the fromJSON method, we convert any objects found in the charts key of the individual sheets object from a spreadjs chart to using the external library chart as a floating object.

    So the two cases if we make the change to use sheets-io module would be handling the legacy case of loading any json structures with the .fromJSON method using the old structure of charts key in the sheets object as well as the new case of loading with a structure of charts being a part of the shapes object instead

  • Posted 10 February 2025, 6:56 am EST - Updated 10 February 2025, 7:01 am EST

    Hi,

    As I understand, you are using SSJSON to retrieve the chart and convert it into a floating object.

    There are two scenarios when loading the JSON:

    • If the JSON follows the old structure, charts will be present under the chart key at the sheet level. In this case, you can directly access and process them from the chart object.

    • If the JSON follows the new structure, charts will be stored under shapes. You need to check if any shape has shapeType = 8 (refer to the attached image), which indicates that it is a chart. You can then convert it into a floating object as needed.

    Also, please note that SpreadJS supports backward compatibility, meaning older SSJSON can be used in newer versions. Since SSJSON is used internally by SpreadJS, its structure may change in future versions.

    Therefore, if you need to access charts reliably, it is recommended to use the API sheet.shapes.all(): https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Sheets.Shapes.ShapeCollection#all

    instead of SSJSON.

    Regards,

    Priyam

Need extra support?

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

Learn More

Forum Channels