Out of Memory Error When Importing Large Excel Files via Base64 in SpreadJS

Posted by: luisdaniel.madrigal on 18 July 2025, 2:20 pm EST

  • Posted 18 July 2025, 2:20 pm EST - Updated 18 July 2025, 2:21 pm EST

    Dear MESCIUS Support Team,

    I hope this message finds you well.

    We are currently using the SpreadJS library with TypeScript in our project, and we’re facing a performance issue when importing Excel files encoded in base64 format. Specifically, when the base64 string is around 25MB, importing the file via the SDK causes the browser to freeze and eventually throws the following error:

    Error code: Out of Memory

    Below is the code we’re using to handle the import:

    function importWorkbookFromBase64(workbook: GCType.Spread.Sheets.Workbook, workbookData: any) {
        if (!workbookData?.base64Data) {
            console.error('Workbook data is not provided or base64Data is missing');
            return;
        }
        if (!workbook) {
            console.error('Workbook is not initialized');
            return;
        }
        workbook.suspendPaint();
        const base64 = workbookData.base64Data;
        const binaryString = atob(base64);
        const len = binaryString.length;
        if (len === 0) {
            console.error('Base64 data is empty');
            return;
        }
        const bytes = new Uint8Array(len);
        for (let i = 0; i < len; i++) {
            bytes[i] = binaryString.charCodeAt(i);
        }
        const file = new File([bytes], "workbook.xlsx", {
            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            lastModified: Date.now()
        });
        workbook.import(file, () => {
            console.log("Workbook loaded successfully.");
            settingUpWorkbookSheets(workbook);
            workbook.resumePaint();
        }, (e) => {
            console.log(e);
            workbook.resumePaint();
        });
    }
    

    Questions:

    1. Are there any best practices or recommended approaches for importing large Excel files (20MB+)?
    2. Is there an optimized or alternative method you recommend when working with large base64 files in SpreadJS?
    3. Do you have any official documentation regarding size limitations or memory handling for file imports via the SDK?

    Notably, when we try importing the same large file via the Spread Designer import UI, it does eventually load (after ~1 minute), so it seems the library can technically process it—though the SDK-based approach causes memory issues.

    We would greatly appreciate any insights, optimizations, or official limitations you could provide.

    Best regards,

  • Posted 21 July 2025, 3:06 am EST

    Hi,

    Based on my understanding, you’re encountering out-of-memory issues while importing a large file.

    Here’s a point-by-point response to your queries:

    1. Best Practices for Loading Large Excel Files

      It’s recommended to load large Excel files using incremental or lazy mode.

    In incremental mode, the file is loaded in the background when the user is idle, allowing UI interactions to continue smoothly.

    In lazy mode, only essential data is loaded initially, and additional data is fetched progressively as needed. This improves performance and reduces memory load at startup.

    Additionally, you can consider converting large Excel files to the SJS format (SpreadJS’s native format, a zipped JSON structure). This format significantly reduces file size and improves load performance for large datasets.

    1. We recommend using Blob or ArrayBuffer instead of decoding the base64 manually. For example, if you receive a base64 file from a backend, consider converting it server-side to binary and sending it as a file download or streaming API.

    2. Understanding File Size Limitations

      SpreadJS does not impose a hard file size limit, so you won’t get a “File is too big” exception. However, the browser’s available memory determines the actual limits. For example, a 5MB Excel file may expand into hundreds of MBs in memory depending on the content (formulas, formatting, data). This can lead to crashes or sluggish behavior based on content complexity rather than file size alone.

    Additional Suggestions

    If the issue persists, please share a minimal reproducible sample so we can further investigate.

    Resources

    Regards,

    Priyam

Need extra support?

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

Learn More

Forum Channels