V the Following Script Demonstrates How to Export a Coach Table As an Excel File

V the Following Script Demonstrates How to Export a Coach Table As an Excel File

<p>1 Introduction  Often times a table in a Coach contains information that the user would like a local copy in a format such as CSV or Excel.  The following script demonstrates how to export a Coach Table as an Excel file.</p><p>2 Table Export Script  Please follow the steps mentioned below in order to use this your application,  Drag 'Custom HTML' component from your coach palette.  Copy paste the script mentioned below.</p><p><a href="javascript:doSubmitExport()">Export</a> <script></p><p>//Modify the value of these variable for your coach var tableIdsToExport = "Table0,Table1"; </p><p>// a comma delimited list of the ids of the tables that you want to include in the excel export // if you include a tableId that does not exist in your coach, you will recieve a client side error message</p><p>//You do not need to modify the following part of the script</p><p> var form = document.createElement('div'); form.innerHTML = '<form name="exportData" method="post" target="_new" action="data-redirect.jsp"><input type="hidden" name="contentType" value="text/csv"><input type="hidden" name="data" value=""><input type="hidden" name="fileName" value="filename=reportData.csv"></form>'; //Work around a bug in IE: http://support.microsoft.com/default.aspx/kb/927917 document.getElementsByTagName("H1")[0].appendChild(form); //document.body.appendChild(form);</p><p> function addExportData(csvTable) { if (document.forms.exportData == null || document.forms.exportData.data == null) { return; } document.forms.exportData.data.value = document.forms.exportData.data.value + "\n\n" + csvTable; } function doSubmitExport() { var tableArr = tableIdsToExport.split(","); for (var i=0;i<tableArr.length;i++) { addTableToCSV(tableArr[i]); } document.forms["exportData"].submit(); }</p><p> function addTableToCSV(tableId) { var table;</p><p> try { table = document.getElementById(tableId);</p><p> var a = table.innerHTML;</p><p>//replace existing commas with semi-colons. Poor mans way of handling embedded commas in a csv file a = a.replace(/,/g, ";");</p><p>//insert commas at the end of a table cell a = a.replace(/<\/td>/g, ","); a = a.replace(/<\/TD>/g, ","); a = a.replace(/<\/th>/g, ","); a = a.replace(/<\/TH>/g, ",");</p><p>//insert a newline tag at the end of every row. Need to do this before removing all tags a = a.replace(/<\/tr>/g, "---newline---"); a = a.replace(/<\/TR>/g, "---newline---");</p><p>//remove html tags a = a.replace(/<\/?[^>]+(>|$)/g, "");</p><p>//remove whitespace (regexs found via google) a = a.replace(/\r/g, " "); a = a.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, ""); a = a.replace(/'/g, ""); a = a.replace(/ +/g, " "); a = a.replace(/^\s/g, ""); a = a.replace(/\s$/g, "");</p><p>//put newlines in a = a.replace(/---newline---/g, "\n");</p><p>//replace &nbsp which the coach designer inserts a = a.replace(/\&nbsp;/g, " ");</p><p>//a now holds a resonable csv that I can put in excel //alert(a); addExportData(a); return true; } catch (e) { alert("Table Export Error: " + e); } return true; } </script></p><p> Modify the information mentioned in the line 5. var tableIdsToExport = "Table0,Table1"; Note: provide a comma delimited list of the ids of the tables that you want to include in the excel export.  It shall display Excel export icon on the coach.  Once user clicks on the icon it exports all the table information in to a CSV file.</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us