473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to Export to excel keeping text colour same ?

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:



Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <script type="text/javascript">
  5.  
  6. function CreateExcelSheet()
  7. {
  8.  
  9.  
  10. var x=myTable.rows
  11.  
  12. var xls = new ActiveXObject("Excel.Application")
  13. xls.visible = true
  14. xls.Workbooks.Add
  15. for (i = 0; i < x.length; i++)
  16. {
  17. var y = x[i].cells
  18.  
  19. for (j = 0; j < y.length; j++)
  20. {
  21. xls.Cells( i+1, j+1).Value = y[j].innerText
  22. }
  23. }
  24.  
  25. }
  26. </script>
  27.  
  28.  
  29. </head>
  30.  
  31. <body marginheight="0" marginwidth="0">
  32. <form>
  33. <input type="button" onclick="CreateExcelSheet()" value="Export to Excel !">
  34. </form>
  35. <table id="myTable" border="1">
  36.  <tr>
  37.         <td>Test</td>
  38. <td><font color="red">Test</td>
  39. <td>Test</td>
  40. <td>Test</td>
  41. <td>Test</td>
  42.     </tr>
  43.  
  44.  <tr>
  45.         <td>Test</td>
  46. <td>Test</td>
  47. <td>Test</td>
  48. <td>Test</td>
  49. <td>Test</td>
  50.     </tr> 
  51. <tr>
  52.         <td>Test</td>
  53. <td>Test</td>
  54. <td>Test</td>
  55. <td>Test</td>
  56. <td>Test</td>
  57.     </tr> 
  58. <tr>
  59.         <td>Test</td>
  60. <td>Test</td>
  61. <td>Test</td>
  62. <td>Test</td>
  63. <td>Test</td>
  64.     </tr>
  65. </table>
  66.  
  67. </body>
  68. </html>
Nov 20 '09 #1
1 2676
rnd me
427 Expert 256MB
a couple other tricks to try:

in head:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     <style type="text/css">
  3.             .green {color:green;}
  4.         </style>
  5.  
  6.  

in table:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <tr>
  3.         <td>Test</td>
  4. <td>Test</td>
  5. <td class="green">Test</td>
  6. <td style="color:blue">Test</td>
  7. <td>Test</td>
  8.     </tr> 
  9.  
Nov 21 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Robin Cushman | last post by:
Hi all, I need some help -- I'm working with an A2K database, using DAO, and am trying to read records into a Crystal Report and then export it to a folder on our network as an Excel...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
1
by: forumaic | last post by:
Hello, I am trying to export data to excel from datagrid, and I am getting an error: "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)." ...
5
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
by: JawzX01 | last post by:
Hello All, First, thank you for any help you can provide. I'm trying to do a simple export to excel. I've used the classic code that is all over the internet, and of course it worked without a...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
0
by: johnlim20088 | last post by:
Hi, Hi, currently I have a code below on my Listcontact.aspx file to export my gridview data to excel:- It is work success, and export the 'Contacts.xls' to my folder. But have following...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.