0

I am new to alasql and I would like to export several data in specific cell using alasql,

for example data1 goes do D4, data2 goes to G3, ..., data_n goes to F3

To do that I use the following javascript/alasql code:

window.saveFile = function saveFile () {
            var data1 = [{a:"Hi",b:"Hey"},{a:"test",b:"test2"}];
            var data2 = [{a:100,b:10},{a:200,b:20}];
            var opts = [{sourcefilename:"test.xlsx", header:false, range:"D13", sheetid:"RECTO"},{sourcefilename:"test.xlsx", header:false, range:"G4", sheetid:"VERSO"}];
            var res = alasql('SELECT * INTO XLSX("myxlsx.xlsx",?) FROM ?',[opts,[data1,data2]]);
        }

As you can see, I would like my data to go to some specific cell from a sourcefile document (an xlsx file with an empty table) Theses data would go to D13 and G4 in the sheet named "RECTO" and "VERSO"

However, when I open my output files, I can observe that:

  • My output does not look to my sourcefile (I've checked and "test.xlsx" is in my directory)
  • My headers are visible even if I put "header:false"

If anyone know how to fix my mistakes, it would help me A LOT

N_G
  • 15
  • 5

2 Answers2

0

Okay, I found out what was going on. I had an old version of alasql in my project. So I upgrade it and then I found this helpful link where the developers explain how to do it.

var data1 = [{a:"Hi",b:"Hey"},{a:"test",b:"test2"}];
var data2 = [{a:100,b:10},{a:200,b:20}];
var opts = [{sourcefilename:"test.xlsx", header:false, range:"D13", sheetid:"RECTO"},
            {sourcefilename:"test.xlsx", header:false, range:"G4", sheetid:"VERSO"}];
var res = alasql('SELECT * INTO XLSX("myxlsx.xlsx",?) FROM ?',[opts,[data1,data2]],
function(){
done();
});

Please checkout this link: https://github.com/agershun/alasql/wiki/How-to-create-multiple-worksheets-into-a-workbook

Belayet Riad
  • 319
  • 4
  • 13
  • I tried your code and it seems we can't use {header:false} inside a {}, i tried without and nothing change – N_G Jun 09 '21 at 12:25
  • 1
    try this var data1 = [{a:"Hi",b:"Hey"},{a:"test",b:"test2"}]; var data2 = [{a:100,b:10},{a:200,b:20}]; var opts = [{sourcefilename:"test.xlsx", header:false, range:"D13", sheetid:"RECTO"}, {sourcefilename:"test.xlsx", header:false, range:"G4", sheetid:"VERSO"}]; var res = alasql('SELECT * INTO XLSX("myxlsx.xlsx",?) FROM ?',[opts,[data1,data2]], function(){ done(); }); – Belayet Riad Jun 10 '21 at 08:49
  • I tried, export works but sourcefile does not (it sent data to a blank excel) – N_G Jun 10 '21 at 10:35
0

header problem is fixed, I replaced header: by headers: in both " { " brackets and it works, remains the problem of the source file

var opts = [{sourcefilename:"test.xlsx", headers:false, range:"D13", sheetid:"RECTO"},{sourcefilename:"test.xlsx", headers:false, range:"G4", sheetid:"VERSO"}];
N_G
  • 15
  • 5