Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Description

Users could only import one sheet at a time from XLSX files. This adds support for importing multiple sheets in a single operation.

Changes

API additions:

  • sheetid: "*" - imports all sheets from workbook
  • sheetid: ['Sheet1', 'Sheet2'] - imports specific sheets by name
  • sheetid: [0, 1] - imports specific sheets by index

Behavior:

  • Multi-sheet imports return flat array with _sheet property on each row identifying source sheet
  • Single sheet imports unchanged (no _sheet property added)
  • Full backward compatibility maintained

Implementation:

  • Refactored XLSXLSX function in src/84from.js to extract sheet processing into processSheet helper
  • Added multi-sheet detection and concatenation logic
  • Added comprehensive test suite in test/test848.js with dedicated test848.xlsx file

Example

// Import all sheets
alasql('SELECT * FROM XLSX("data.xlsx", {sheetid: "*"})', [], function(data) {
  console.log(data[0]._sheet); // "Sheet1"
});

// Query specific sheet
alasql('SELECT * FROM XLSX("data.xlsx", {sheetid: "*"}) WHERE [_sheet] = "Sheet2"', [], cb);

// Aggregate by sheet
var data = alasql('SELECT * FROM XLSX("data.xlsx", {sheetid: "*"})');
var counts = alasql('SELECT [_sheet], COUNT(*) FROM ? GROUP BY [_sheet]', [data]);

Testing

  • 7 new tests in test/test848.js covering all multi-sheet scenarios
  • Dedicated test848.xlsx file for testing (not reusing files from other tests)
  • All 506+ existing tests pass
  • CodeQL: 0 vulnerabilities

Checklist

  • Code follows project style guidelines
  • Tests added for new functionality
  • All tests passing
  • Documentation updated (via examples in tests)
  • Backward compatibility maintained

Fixes #848

Original prompt

This section details on the original issue you should resolve

<issue_title>Import xlsx with multiple sheets</issue_title>
<issue_description>I'm using alasql to generate an xlsx with multiple worksheets as a template.

What i need to do now is import this same file but after some user fill them with data. My problem is i'm not being able to import all 3 sheets from it. Don't know if it's implemented already.

i was looking for this issue opened #848
but i do not know what happend from there. Thanks and sorry if this doesn't belong here.

</issue_description>

<agent_instructions>Is this something you can look at?</agent_instructions>

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

@mathiasrw @EzePerucca As far as I know no one have put the time in to fix this.

💡 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 November 20, 2025 01:07
- Add support for importing all sheets using sheetid: "*"
- Add support for importing specific sheets using sheetid: [sheet1, sheet2, ...]
- Returns flat array with _sheet property added to each row
- Maintains backward compatibility with single sheet imports
- All existing XLSX tests pass

Co-authored-by: mathiasrw <[email protected]>
Copilot AI changed the title [WIP] Fix import of xlsx file with multiple sheets Add multi-sheet import support for XLSX files Nov 20, 2025
Copilot AI requested a review from mathiasrw November 20, 2025 01:14
Copilot finished work on behalf of mathiasrw November 20, 2025 01:14
Copy link
Member

@mathiasrw mathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Please make sure the name the test file test848.js

I would expect this test to have its own EXCEL example files named something with test848.*

Dont use excel files from other tests. Copy and rename if you must.

- Renamed test-multisheet-import.js to test848.js
- Created dedicated test848.xlsx file (copied from test242.xlsx)
- Updated all test references to use test848.xlsx instead of test242.xlsx
- All 7 tests passing

Co-authored-by: mathiasrw <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot

Please make sure the name the test file test848.js
...

Done. Renamed the test file to test848.js and created a dedicated test848.xlsx file. All references updated and tests passing. (620505f)

Copilot AI requested a review from mathiasrw November 20, 2025 05:48
Copilot finished work on behalf of mathiasrw November 20, 2025 05:48
@mathiasrw mathiasrw marked this pull request as ready for review November 20, 2025 08:54
@mathiasrw mathiasrw merged commit 38ecf79 into develop Nov 20, 2025
10 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.

Import xlsx with multiple sheets Import and Read multiple sheets of Excel file through browser using alasql?

2 participants