When I use export form Hnadsontable to excel I get information from whole table in one column in excel. I want to one column of the table match to one column of excel. How to do it?
Second thing – How add some information to export excel? For example which filter was used.
Hi @pranosz
You can export a file as a .csv not as an Excel file (.xls, .xlsx) and the .csv is a plain text. You need to set a separator while importing the .csv file.
When you select a ‘comma’ you should see that the data is being separated.
The only options for this plugin are:
(source: Export to CSV - JavaScript Data Grid | Handsontable)
exportHiddenRows: boolean // default false
exportHiddenColumns: boolean // default false
columnHeaders: boolean // default false
rowHeaders: boolean // default false
columnDelimiter: char // default ‘,’
range: array // [startRow, endRow, startColumn, endColumn]
Thank you for quick answer. I found example where export works just like I want (http://jsfiddle.net/9Lf0n9wh/1/) - click on “Export as a File (semicolon as delimiter)”, but I don’t know how to implement this solution in my project. I can’t find information about createSpreadsheetData method.
createSpreadsheetData
is a helper method for Handsontable.
It’s only used in our Support demos to generate an array of strings like in this example
Handsontable.helper.createSpreadsheetData(3, 7)
will create a table with 3
rows and 7
columns.
Of course in your example the data
parameter will be filled with your data.
Going further only this code is an export logic
var exportPlugin = hot.getPlugin('exportFile');
toFileTAB.addEventListener('click', function() {
exportPlugin.downloadFile('csv', {
columnHeaders: true, // default false, exports the column headers
rowHeaders: true, // default false, exports the row headers
columnDelimiter: '\t', // data range in format: [startRow, endRow, startColumn, endColumn]
});
});
toFileSEMI.addEventListener('click', function() {
exportPlugin.downloadFile('csv', {
columnHeaders: true, // default false, exports the column headers
rowHeaders: true, // default false, exports the row headers
columnDelimiter: ';', // data range in format: [startRow, endRow, startColumn, endColumn]
});
});
and the first line
var exportPlugin = hot.getPlugin('exportFile');
takes your instance as a source of data. The hot
is a name of your Handsontable instance.
The second and the last thing to do is to create the HTML structure (buttons)
It works – Now I have separated columns in excel. Thank you.
But I have another question. It is possible to put in excel some additional information before the table?
When you already loaded the table into Excel you can change anything you want it’s a plain text. You can add anything below, above or between cells.
I’m talking about adding information dynamically – from javascript. As it works for tables.
currently you can only export a last state of your table as a plain text table.