Skip to content

Commit

Permalink
Fix #1109 (#1872)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkkachi authored Feb 3, 2024
1 parent fd84d77 commit df396b6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
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]);
});
});

0 comments on commit df396b6

Please sign in to comment.