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.
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.
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
The <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.
Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”. document.
An HTML hidden attribute indicates that the element is not yet or is no longer relevant. If something is marked as 'hidden' in the CSS, this makes the element hidden from search engines, making it impossible to display and invisible even to screen readers.
In Chrome, Safari, Opera and Firefox (with Firebug add-on) right click and choose Inspect Element (or Inspect Element with Firebug) and it will show you all elements and the style rules that apply to them. The Web Developer Toolbar for Firefox has a “Show hidden elements” option under the “Miscellaneous” menu.
Use the new data- attributes
http://www.javascriptkit.com/dhtmltutors/customattributes.shtml
<div data-row="[["Musicals",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 "
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With