Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Description

The sourcefilename option for updating existing Excel files had a critical bug: the callback was invoked before async file loading completed, causing files not to be created and test failures.

Changes

Fixed async callback timing in src/833xlsx.js:

  • Moved callback invocation inside the loadBinaryFile async callback for the sourcefilename path
  • Non-sourcefilename path remains synchronous as before

Added comprehensive test coverage in test/test107-B.js (8 tests total):

  • Loading existing Excel files with sourcefilename parameter
  • Positioning data at specific cells with range parameter (e.g., "B3", "E5", "AA5")
  • Headers on/off, sheet creation, and file overwriting scenarios
  • Content verification: Each test reads back the generated XLSX files using SELECT FROM XLSX() and validates using assert.deepEqual():
    • Data is written at the correct positions
    • Original data is preserved when using sourcefilename
    • Headers are correctly included/excluded based on the headers option
    • Multiple sheets can coexist in the same workbook
    • Multi-letter column positions (like AA) work correctly
  • Async/Promise flow validation: Added 2 async/await tests to confirm:
    • Promise-based operations work correctly with alasql.promise()
    • Async flow for sourcefilename and range operations
    • Promise-based flow for multi-sheet creation

Usage

// Update existing spreadsheet at specific location (callback style)
alasql('SELECT HOUR(NOW()), MINUTE(NOW()), SECOND(NOW()) \
    INTO XLSX("output.xlsx", { \
        sourcefilename: "template.xlsx", \
        sheetid: "Sheet1", \
        range: "B3", \
        headers: false \
    })', [], function(res) {
    // Callback invoked after file is written
});

// Using promises/async-await
await alasql.promise(
    'SELECT * INTO XLSX("output.xlsx", { \
        sourcefilename: "template.xlsx", \
        sheetid: "Sheet1", \
        range: "B3", \
        headers: false \
    }) FROM ?',
    [data]
);

The feature now correctly:

  • Loads the source file asynchronously
  • Writes data starting at the specified cell
  • Invokes callbacks after completion
  • Preserves existing data in the source file
  • Supports both callback and promise-based async patterns
Original prompt

This section details on the original issue you should resolve

<issue_title>Update existing Excel spreadsheet with INTO XLSX()</issue_title>
<issue_description>I had a specific question related to the export to excel (xlsx).

I am working with AngularJS and looking to use your library to export data from an application into a spreadsheet. I want to SELECT INTO a spreadsheet that already exists and starting at a specific row and column. In the examples I have found and the attempt that I have tried, I can only export to a new file and the export always starts at A1.

Is there a way to do what I have explained?
</issue_description>

<agent_instructions>name the test file test/test107-B.js</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@agershun I have added two new experimental flags to INTO XLSX function: - sourcefilename - your basic file (if filename and sourcefilename are the same, the basic file will be overwritten) - range - left upper corner of range

This is an example:

    alasql('SELECT HOUR(NOW()), MINUTE(NOW()), SECOND(NOW()) \
        INTO XLSX("test251.xlsx",{sourcefilename:"test251.xlsx", \
          sheetid:"test2", range:"B3", headers:false})',[],function(res){
    });
@mathiasrw > I have added two new experimental flags

Shuold we include this in the wiki and close the issue or is it too experimental yet?

@mathiasrw Nothing new @mathiasrw Please make a new issue if its not related to the existing one. Its a known bug. Please let us know if you find a solution.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 7, 2025 06:25
…x async callback bug

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copilot AI changed the title [WIP] Update existing spreadsheet with INTO XLSX functionality Fix async callback bug in XLSX export with sourcefilename option Dec 7, 2025
Copilot AI requested a review from mathiasrw December 7, 2025 06:31
… data

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copilot AI changed the title Fix async callback bug in XLSX export with sourcefilename option Fix async callback bug in XLSX export with sourcefilename option and add content verification tests Dec 8, 2025
Copilot AI requested a review from mathiasrw December 8, 2025 01:29
Copilot AI and others added 2 commits December 8, 2025 22:59
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
…queries

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copilot AI changed the title Fix async callback bug in XLSX export with sourcefilename option and add content verification tests Fix async callback bug in XLSX export with sourcefilename option and add comprehensive test coverage Dec 8, 2025
Copilot AI requested a review from mathiasrw December 8, 2025 23:05
@mathiasrw mathiasrw marked this pull request as ready for review December 11, 2025 01:56
@mathiasrw mathiasrw merged commit fcc3e21 into develop Dec 11, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update existing Excel spreadsheet with INTO XLSX()

2 participants