Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser
Excel export script works on IE7+, Firefox and Chrome.
function fnExcelReport()
{
var tab_text="<table border='2px'><tr bgcolor='#87AFC6'>";
var textRange; var j=0;
tab = document.getElementById('headerTable'); // id of table
for(j = 0 ; j < tab.rows.length ; j++)
{
tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
//tab_text=tab_text+"</tr>";
}
tab_text=tab_text+"</table>";
tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
{
txtArea1.document.open("txt/html","replace");
txtArea1.document.write(tab_text);
txtArea1.document.close();
txtArea1.focus();
sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
}
else //other browser not tested on IE 11
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
Just create a blank iframe:
<iframe id="txtArea1" style="display:none"></iframe>
Call this function on:
<button id="btnExport" onclick="fnExcelReport();"> EXPORT </button>
Export as Excel file not working for HTML table in Chrome Extension
Your problem is in the way you specify multiple script dependencies in the manifest:
"js": ["timetable.js"],
"js": ["jquery.js"]
In JSON, the latter entry will simply overwrite the former, so now you no longer reference timetable.js
The value for the "js" key is already an array (as denoted by the [ ]), so you just add your dependencies to that array:
"js": ["timetable.js", "jquery.js"]
I'm not sure in what order the scripts are injected, you might need to switch them around.
jQuery does not works when exporting html table to excel
After talking with @MohitKumar and @FedericoklezCulloca i tied to do it like this:
$table = '<table>';
$table .= '<thead>';
$table .= '<tr>';
$table .= '<th>product</th>';
$table .= '<th>value</th>';
$table .= '</tr>';
$table .= '</thead>';
$table .= '<tbody>';
$result = mysqli_query($conn, "SELECT product, value FROM my_table");
while($row = mysqli_fetch_array($result)){
$table .= '<tr>';
$table .= '<td>'.$row['product'].'</td>';
$table .= '<td>'.$row['value'].'</td>';
$table .= '</tr>';
$abAmount += $row['value'];
}
$table .= '</tbody>';
$table .= '</table>';
echo '<br>THAT VALUE HERE: '.$abAmount.'<br>';
echo $table;
And it did work!
Export HTML table to Excel file
Managed to fix it. I initially suspected that not putting it inside the ready function would be a problem and thought it would fix the issue, but that was only part of the problem. I also forgot a comma. The finished result is as follows.
<script>
$(document).ready(function() {
//activate footable jquery plugin (this is the dynamic table on the report page with search and sorting functions)
$('.footable').footable();
//Prepare table2excel plugin (clicking the export button will send the main table to an Excel spreadsheet)
$("button.excelexport").click(function(){
$("#footable").table2excel({
//Exclude CSS class specific to this plugin
exclude: ".noExl",
name: "Merchandising Report",
filename: "merchReportTable"
});
});
});
</script>
Display HTML table from xml file over web browser without using any software or installation on unix
This should solve your issue (as asked), using pandas:
import pandas as pd
xml_data = '''<?xml version="1.0" encoding="UTF-8"?>
<chapter name="ndlkjfidm" date="dfhkryi">
<edge name="nnn" P="ffgnp" V="0.825" T="125c">
<seen name="seen1">
</seen>
<seen name="ABB">
<mob name="adas_jk3" type="entry">
<nod name="VSS" voltage="0.000000" vector="!ENXB" active_input="NA" active_ouput="ENX">
<temp name="ADS_DEFAULT_temp_LOW">
<raw nod="VBP" alt="7.05537e-15" jus="74.4619" />
<raw nod="VDDC" alt="4.63027e-10" jus="115.178" />
<raw nod="VDDP" alt="6.75316e-10" jus="115.178" />
<raw nod="VSS" alt="5.04568e-14" jus="9.63935" />
<raw nod="VBN" alt="1.21047e-14" jus="192.973" />
<raw nod="VBP" trip="4.58141e-12" />
<raw nod="VDDC" trip="5.19549e-09" />
<raw nod="VDDP" trip="5.49458e-08" />
<raw nod="VSS" trip="6.00563e-08" />
<raw nod="VBN" trip="8.94924e-11" />
</temp>
</nod>
<nod name="VSS" voltage="0.000000" vector="ENXB" active_input="NA" active_ouput="ENX">
<temp name="ADS_DEFAULT_temp_HIGH">
<raw nod="VBP" alt="7.05537e-15" jus="74.4644" />
<raw nod="VDDC" alt="1.52578e-14" jus="311.073" />
<raw nod="VDDP" alt="1.00188e-14" jus="521.709" />
<raw nod="VSS" alt="4.03483e-14" jus="11.1118" />
<raw nod="VBN" alt="1.21047e-14" jus="192.975" />
<raw nod="VBP" trip="4.58141e-12" />
<raw nod="VDDC" trip="1.29302e-12" />
<raw nod="VDDP" trip="4.92723e-08" />
<raw nod="VSS" trip="4.91887e-08" />
<raw nod="VBN" trip="8.95356e-11" />
</temp>
</nod>
</mob>
</seen>
</edge>
</chapter>
'''
One option to read the xml would be:
df = pd.read_xml(xml_data)
# df
html = df.to_html()
print(html)
Result:
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>name</th>
<th>P</th>
<th>V</th>
<th>T</th>
<th>seen</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>nnn</td>
<td>ffgnp</td>
<td>0.825</td>
<td>125c</td>
<td>NaN</td>
</tr>
</tbody>
</table>
Related Topics
Disable Interpolation When Scaling a ≪Canvas≫
Pass a String Parameter in an Onclick Function
How to Prevent a Click on a '#' Link from Jumping to Top of Page
Restricting Input to Textbox: Allowing Only Numbers and Decimal Point
How to Draw an Inline Svg (In Dom) to a Canvas
How to Clear the Contents of an Iframe from Another Iframe
Selecting All Text in HTML Text Input When Clicked
How to Set Value of Input Text Using Jquery
How to Add/Remove Several Classes in One Single Instruction With Classlist
Stopping Gif Animation Programmatically
Get the Position of a Div/Span Tag
Retrieving the Text of the Selected ≪Option≫ in ≪Select≫ Element
Force a Browser to Save File as After Clicking Link
Execute PHP Function With Onclick
How to Validate Inputs Dynamically Created Using Ng-Repeat, Ng-Show (Angular)