Hi all,
I have a simple code that exports an HTML table on an ASP page to excel.
The code works fine, however if the original text in the HTML table had a particular colour, it is not exported in the same way.The resulting excel file has all text black only.
Pls. suggest how to solve this problem.
Any help would be greatly appreciated .
Here's the code:
I have a simple code that exports an HTML table on an ASP page to excel.
The code works fine, however if the original text in the HTML table had a particular colour, it is not exported in the same way.The resulting excel file has all text black only.
Pls. suggest how to solve this problem.
Any help would be greatly appreciated .
Here's the code:
Code:
<html>
<head>
<script type="text/javascript">
function CreateExcelSheet()
{
var x=myTable.rows
var xls = new ActiveXObject("Excel.Application")
xls.visible = true
xls.Workbooks.Add
for (i = 0; i < x.length; i++)
{
var y = x[i].cells
for (j = 0; j < y.length; j++)
{
xls.Cells( i+1, j+1).Value = y[j].innerText
}
}
}
</script>
</head>
<body marginheight="0" marginwidth="0">
<form>
<input type="button" onclick="CreateExcelSheet()" value="Export to Excel !">
</form>
<table id="myTable" border="1">
<tr>
<td>Test</td>
<td><font color="red">Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
</table>
</body>
</html>
Comment