Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  168] [ 7]  / answers: 1 / hits: 37713  / 14 Years ago, thu, january 20, 2011, 12:00:00

I produce a complex HTML summary report from data in a database which could be a summary of maybe 200,000 rows in the database. The user can click a link to request an Excel version.



When they do a JS script extracts the key components of the report and stuffs them into a form in a hidden iframe. This form submits to a server-side script which generates the Excel version of the report (without the graphics etc).



As the calculations for the report are complex and costly it makes sense not to run them again to create the Excel version as all the data is on the page already. Also the user may have customised the report once it is loaded and I can use JS to pass those preferences to the form as well so the Excel doc reflects them too.



The way I am doing this is to include the following for each component of the report that transfers to a row in the Excel version. I've hijacked an HTML tag that isn't otherwise used.



   <code id=xl_row_211865_2_x class=rowlabel>Musicals}{40%}{28.6%}{6</code>


The code element above is a summary of the row below in the HTML report which becomes one row in the Excel doc and includes the label and various data elements. There may be a thousand or more such elements in one report.



alt



As the data contains text I've had to use something like }{ as a field separator as this is unlikely to occur in any real text in the report. I have code set to display:none in the CSS.



When the user wants an Excel version of their report the JS code searches the HTML for any <code> elements and puts their className and innerHTML in the form. The className indicates how to format the row in Excel and the data is then put into adjacent cells on the Excel row.



alt



The HTML report shows one percentage base (they can toggle between them) but the user preference when requesting an Excel version was to include both.



Is there a better way of doing this?



(As this is a part of a complex web app no user is going to turn CSS off or lack javascript or they wouldn't get this far)
ADDED: I can't use HTML5 as the users are corporates often on older browsers like IE6


More From » html

 Answers
48

Use the new data- attributes



http://www.javascriptkit.com/dhtmltutors/customattributes.shtml



<div data-row=[[&quot;Musicals&quot;,40,28.6,6], ...]>


The div could be the TD tag or TR tag or any other relevant tag already related to the row and the &quot; is the escaped .



That makes the data hidden from view and also ensures that there will come standard solutions to process the data.



Also for encoding data I would suggest using JSON as that is also a standard that is easy to use.


[#94129] Wednesday, January 19, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ellisw

Total Points: 625
Total Questions: 92
Total Answers: 88

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
ellisw questions
Mon, Aug 23, 21, 00:00, 3 Years ago
Fri, Nov 20, 20, 00:00, 4 Years ago
Sat, Jun 20, 20, 00:00, 4 Years ago
Tue, Apr 21, 20, 00:00, 4 Years ago
;