excellentexport
excellentexport copied to clipboard
Merged cell output is only one cell
Hello, I am making good use of the library you provided. Really appreciate it.
But, I have a problem about exporting the Excel file.
I need to export excel file from dynamically created HTML Table with the 'xlsx' extension, but the merged cells are not exported normally, and only one cell is output.
I am wondering if there is an option or method to export merged cells.
Thank you for reading.
Regarding the issue about specifying a cell value as a number:
I had to add some logic to "fixValue:" to return a number instead of a string. You can also use the "row" and "col" to specify entire rows or columns as number or string. Hopefully the example below is helpful.
fixValue: (value, row, col) => {
let v = value.replace(/<br>/gi, "\n");
let strippedString = v.replace(/(<([^>]+)>)/gi, "");
if (col < 4 || col == 6 || col== 7|| col== 8 )
{
return_value = strippedString;
}
else
{
if (isNaN(strippedString) || strippedString == "")
{
return_value = strippedString;
}
else return_value = Number(strippedString);
}
return return_value;
}
First of all, thank you for your comment. However, it doesn't work well.
I wrote the code like this:
let v = value.replace(/<br>/gi, "\n");
let strippedString = v.replace(/(<([^>]+)>)/gi, "");
strippedString = strippedString.replace(" ", "");
if (column < 7 || column > 16){
return_value = strippedString;
}else{
if (isNaN(strippedString) || strippedString == ""){
return_value = strippedString;
}else return_value = Number(strippedString);
}
return return_value;
But, in the downloaded 'xlsx' file, the cell type is still designated as a text (default) type not number, so direct use of the formula is not possible.
It seems that the cell type conversion does not work in the case of the 'xlsx' extension file.
So I edited my title to just about the merged cell output, thanks.
I am using version 3.6.0 of excellantexport and opening it in Office 365 Excel. I hope this helps.
<script src="excellentexport.js"></script>
<h3>Listing </h3>
<script>
function export_tables(format) {
var exportDate = new Date();
var exportDate = exportDate.toISOString();
var exportDate = exportDate.replace("T"," ");
var exportDate = exportDate.substring(0, exportDate.length - 5);
return ExcellentExport.convert({
anchor: 'anchorexport_tables-' + format,
filename: 'exported_table '+ exportDate,
format: format
}, [
{
name: 'Listing',
from: {
table: 'table-VS'
},
fixValue: (value, row, col) => {
let v = value.replace(/<br>/gi, "\n");
let strippedString = v.replace(/(<([^>]+)>)/gi, "");
if (isNaN(strippedString) || strippedString == "")
{
return_value = strippedString;
}
else return_value = Number(strippedString);
return return_value;
}
},
]
)
}
</script>
<BR>
<a href="#" id="anchorexport_tables-xlsx" onclick="return export_tables('xlsx');"><button>Export to Spreadsheet</button></a><BR><BR>
<table id='table-VS'>
<TR><TH>Date</TH><TH>Name</TH><TH>Code</TH></TR>
<TR><TD>2021-01-01</TD><TD>Sam</TD><TH>1</TD></TR>
<TR><TD>2021-04-21</TD><TD>John</TD><TH>2</TD></TR>
<TR><TD>2021-02-11</TD><TD>April</TD><TH>23</TD></TR>
<TR><TD>2021-04-21</TD><TD>Susan</TD><TH>12</TD></TR>
<TR><TD>2021-01-21</TD><TD>Alex</TD><TH>12</TD></TR>
<TR><TD>2020-12-10</TD><TD>Jeff</TD><TH>12</TD></TR>
<TR><TD>2019-06-11</TD><TD>Fred</TD><TH>12</TD></TR>
<TR><TD>2043-04-30</TD><TD>Valli</TD><TH>12</TD></TR>
<TR><TD>2012-04-27</TD><TD>Joe</TD><TH>12</TD></TR>
<TR>
This is an image of the web page and the resulting excel spread sheet. Column C is seen by Excel as numbers.
Thanks for your detailed answer.
However, except for the date part, It seems to be no difference from the code I wrote above. So I think my file should be output as a number cell like you said, but the problem is still occurring. Maybe I'll check a little more, but I think it will be done by exporting to xls.
Thanks, again.
Thanks for your detailed answer.
However, except for the date part, It seems to be no difference from the code I wrote above.
So I think my file should be output as a number cell like you said, but the problem is still occurring.
Maybe I'll check a little more, but I think it will be done by exporting to xls.
Thanks, again.
I'm not sure why my solution doesn't work for you... I hope that you solve it and let me know.
I've been personally been trying to get the exported excel to have some formatting like word wrap, row height and Column width... and maybe some bold text.
I'm not sure why my solution doesn't work for you... I hope that you solve it and let me know.
I've been personally been trying to get the exported excel to have some formatting like word wrap, row height and Column width... and maybe some bold text.
Sure. When this project is over and I have time, I will try it immediately and let you know.
But, there is one idea that comes to mind. In my code, I dynamically form a table, so I think the cell can't be converted to number type because it's some type can't cast to number type. I'll check it later.
I'm facing the same problem, is there any solution for merged cells?
Hello, I see the function ExcellentExport.excel formats different than ExcellentExport.convert. Is it possible to have some formatting like word wrap, row height, Column width, font type, and bold text with the convert function, so it can look more like the file generated with excel function? Thanks.
I started developing this feature. Check the PR: https://github.com/jmaister/excellentexport/pull/678
Now you can define types and formats for ranges of cells. i.e. A1:B5 type Integer, C1:C5 type Date
@carodiu for the row height, column width, etc... I am investigating it now.
Take a look at this PR: https://github.com/jmaister/excellentexport/pull/678
@jmaister Hi. How is your investiage about width and height for row and column?
@sergeushenecz Height and width is something to investigate. Please open a new issue if needed with your example.