Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1109 #1872

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/833xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ alasql.into.XLSX = function (filename, opts, data, columns, cb) {
var dataLength = Object.keys(data).length;

// Generate columns if they are not defined
if ((!columns || columns.length == 0) && dataLength > 0) {
columns = Object.keys(data[0]).map(function (columnid) {
return {columnid: columnid};
});
if (!columns || columns.length == 0) {
if (dataLength > 0) {
columns = Object.keys(data[0]).map(function (columnid) {
return {columnid: columnid};
});
} else {
columns = [];
}
}

var cells = {};
Expand Down
26 changes: 26 additions & 0 deletions test/test1109.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}

describe('Test 1109 - Export empty tables to excel sheets', function () {
const test = '1109';

before(function () {
alasql('create database test' + test);
alasql('use test' + test);
});

after(function () {
alasql('drop database test' + test);
});

it('A) Export empty tables to excel sheets', function () {
var res = [];
var opts = [{sheetid: 'a'}, {sheetid: 'b'}];
res.push(
alasql('SELECT INTO XLSX("' + __dirname + '/restest1109.xlsx",?) FROM ?', [opts, [[], []]])
);
assert.deepEqual(res, [1]);
});
});
Loading