Rectangle 27 4

A great client-side tool for exporting html tables to xlsx, xls, csv, or txt is TableExport by clarketm (me). It is a simple, easy-to-implement, full-featured library with a bunch of configurable properties and methods.

$ npm install tableexport
TableExport(document.getElementsByTagName("table"));

// OR using jQuery

$("table").tableExport();

Check out the compendious docs or just head over to TableExport on Github for a full list of features.

Spoiler alert: pdf support will be part of the upcoming release

javascript - How to export an html table as an xlsx file - Stack Overf...

javascript excel html-table xls xlsx
Rectangle 27 2

You won't be able to export it as XLSX without going back to the server. A XLSX file is a collection of XML files, zipped together. This means you do need to create multiple files. This is impossible to do with JS, client-side.

Instead, you should create a function retrieving the data from your HTML table and send that to you server. The server can then create the XLSX file for you (there are a bunch of libs available for that!) and send it back to the client for download.

If you expect to have a huge dataset, the XLSX creation on the server should be done as an async process, where you notify the user when it's done (instead of having the user waiting for the file to be created).

Then take a look at github.com/SheetJS/js-xlsx. This is probably the most popular library to work with XLSX in Node

@ErdenizKorkmaz Historically speaking ... this "would be" correct. With all modern browsers, even many legacy browsers, this is quite easy to handle, although I wouldn't recommend it for large sets of data (due to performance reasons). Check out the library I wrote: clarketm/TableExport; it leverages SheetJS/js-xlsx behind the scenes to handle the parsing.

javascript - How to export an html table as an xlsx file - Stack Overf...

javascript excel html-table xls xlsx
Rectangle 27 3

  • Filesaver API is new 'HTML5' functionality allowing /exactly/ this. There is just one small problem: the relevant part isn't supported yet in firefox. If you want to use this there is a nice wrapper library which makes this easier for you: filesaver.js
  • Downloadify is a flash tool which is created for exactly this as well, you can find it here. ('Disadvantage': flash)

Tried filesaver.js demo page, worked fine with chrome, in firefox (14.0.1) it only opened a new tab with the contents...and being firefox our target platform.... Downloadify worked fine in firefox but i will have to try to implement it in our website to see if its feasible (asp.net + ajax.net + there are multiple tables to which we added the export as excel button next to each one dinamically by javascript)

Yeah, that's why I said 'the relevant part isn't supported yet in firefox'@filesaver. But as far as I know the downloadify one should work perfectly fine.

asp.net - Export HTML table to Excel JavaScript function add select fi...

javascript asp.net excel export export-to-excel
Rectangle 27 5

<?php>
$colgroup = str_repeat("<col width=86>",5);
$data = "";
$time = date("M d, y g:ia");
$excel = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html>
<head>
<meta http-equiv=\"Content-type\" content=\"text/html;charset=utf-8\" />
<style id=\"Classeur1_16681_Styles\">
.xl4566 {
color: red;
}
</style>
</head>
<body>
<div id=\"Classeur1_16681\" align=center x:publishsource=\"Excel\">
<table x:str border=0 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\">
<colgroup>$colgroup</colgroup>
<tr><td class=xl2216681><b>Col1</b></td><td class=xl2216681><b>Col2</b></td><td class=xl2216681 ><b>Col3</b></td><td class=xl2216681 ><b>Col4</b></td><td class=xl2216681 ><b>Col5</b></td></tr>
<tr><td class=xl4566>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr>
</table>
</div>
</body>
</html>";
  $fname = "Export".time().".xls";
  $file = fopen($fname,"w+");
  fwrite($file,$excel);
  fclose($file);
  header('Content-Type: application/vnd.ms-excel');
  header('Content-Disposition: attachment; filename="'.basename($fname).'"');
  readfile($fname);
  unlink($fname); ?>

javascript - How can I export tables to excel from a webpage - Stack O...

javascript jquery html css table
Rectangle 27 1

If you don't need an original Excel-File, but a file, which displays the columns of your table in Excel (And can be edited within Excel or LibreOffice Calc or many other programs), you should consider using CSV (comma-separated values).

It's easy to create and edit and there is no need of using any PlugIn or Library.

Column Name 1, Column Name 2, Column Name 3
'Row1Val1', 'Row1Val2', 'Row1Val3'
'Row2Val1', 'Row2Val2', 'Row2Val3'
'Row3Val1', 'Row3Val2', 'Row3Val3'

But in case you really want an Excel File, PHPExcel will be your friend. It uses the CSV file to create a fully operational Excel-File.

include 'PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReader('CSV');

// If the files uses a delimiter other than a comma (e.g. a tab), then tell the reader
$objReader->setDelimiter("\t");
// If the files uses an encoding other than UTF-8 or ASCII, then tell the reader
$objReader->setInputEncoding('UTF-16LE');

$objPHPExcel = $objReader->load('MyCSVFile.csv');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('MyExcelFile.xls');

PHP Excel provides a functionality to include images:

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('PHPExcel logo');
$objDrawing->setDescription('PHPExcel logo');
$objDrawing->setPath('./images/phpexcel_logo.gif');       // filesystem reference for the image file
$objDrawing->setHeight(36);            
$objDrawing->setCoordinates('D24');    
$objDrawing->setOffsetX(10);                
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

javascript - Export HTML table to excel with text and images - Stack O...

javascript php jquery html export-to-excel
Rectangle 27 1

I'm not sure if you have done this already. You might need to handle something like this below in your aspx page:

$(window).load(function(){
$( "#clickExcel" ).click(function() {  
var dtltbl = $('#dtltbl').html();    `enter code here`
window.open('data:application/vnd.ms-excel,' + $('#dtltbl').html());
});
});//]]>

In the above script #dtltbl is the Table Id.

The following code needs be there in your server side code, then your problem would be solved.

Response.AddHeader("Content-Disposition", "attachment;filename=myfilename.csv");

Also check this link it might be of useful to you.

The problem with this is that you need to make a postback to the server in order to add the header. The idea of using this function is generate the excel from the client directly throught javascript

This gives an fair appraoch on handling the export without server side code, see if it meets your requriements stackoverflow.com/questions/3286423/

asp.net - Export HTML table to Excel JavaScript function add select fi...

javascript asp.net excel export export-to-excel
Rectangle 27 43

We had the same issue too many complaints from our customers. We traced it to the Excel OFffice Security patch KB3115262 - https://support.microsoft.com/en-us/kb/3115262 Which came out July 12, 2016

To work around the issue, we had customers make a change in their Excel to allow files from the internet.

3) Go to Protected View. there are 3 options that show that were all clicked

We uncheck the first option that reads -- "Enable Protected View for files originating from the Internet"

That fixed the issue. Perhaps not the best solution. I'm not sure why this particular KB broke this but I think perhaps the fact the file format is not expected and this setting are conflicting with each other.

On a computer I have that doesn't have this KB installed, all those are checked and it still works fine (not blank but prompts file format is different) and I think shows in protected view.

What led us to fact its not the content of the file is we noticed if we resave the file in notepad or notepad++ without making any changes, the file behaves fine so excel must be reading some property of the file rather than the content to block it.

Thank you! This helped a lot. For german office users: Datei -> Optionen -> Trust Center -> Einstellungen fr das Trust Center -> Geschtzte Ansicht -> Haken entfernen bei "Geschtzte Ansicht bei Dateien aus dem Internet aktivieren"

Several customer emails and a couple hours of work in, and I find this. Thank you so much!

javascript - Export HTML Table to Excel- Doesn't Open in Office 2010 -...

javascript excel
Rectangle 27 9

Generate the contents of the CSV file as a string in JavaScript (I assume you're not asking SO to just write this code for you), then encode it as Base64 and generate a data: URI with the MIME type text/csv. Redirect the browser to that URI and it should trigger a download dialog for the user.

javascript - Export HTML table to csv file on client side - Stack Over...

javascript html
Rectangle 27 1

<?php
    mysql_connect("localhost","root","");
    mysql_select_db("school");
?>

<html>
    <head>
        <script type="text/javascript" src="../js/exp_stdsub.js"></script>
    </head>
       <hr />
                            <u><h3>Export your Data here</h3></u>
                            <form action="" method="post"> 
                                        <select name="expstd" id="expstd" onclick="return expsubjs(this.value);">
                                            <option>Select Standared</option>
                                    <?php
                                        $exe_sel_std = mysql_query("SELECT * from s_standared");
                                        while($r_sel_std = mysql_fetch_array($exe_sel_std)){
                                            $sel_stdid = $r_sel_std['std_id'];
                                            $sel_std = $r_sel_std['std']; ?>
                                            <option value="<?php echo $sel_stdid; ?>"><?php echo $sel_std; ?></option>
                                            <?php  } ?>
                                            </select></td>


                                <input type="submit" class="btn btn-green" name="exp_stdque" value="Export Standardwise Question">

                            </form>
                        </table>

<?php

//EDIT YOUR MySQL Connection Info:
$DB_Server = "localhost";        //your MySQL Server
$DB_Username = "root";                 //your MySQL User Name
$DB_Password = "";                //your MySQL Password
$DB_DBName = "school";                //your MySQL Database Name
$DB_TBLName = "s_question";                //your MySQL Table Name

if(isset($_POST['exp_stdque'])) {
    $exstdid = $_POST['expstd'];

//$DB_TBLName,  $DB_DBName, may also be commented out & passed to the browser
//as parameters in a query string, so that this code may be easily reused for
//any MySQL table or any MySQL database on your server

//DEFINE SQL QUERY:
//edit this to suit your needs
$sql = "Select * from $DB_TBLName WHERE std_id = $exstdid";

//Optional: print out title to top of Excel or Word file with Timestamp
//for when file was generated:
//set $Use_Titel = 1 to generate title, 0 not to use title
$Use_Title = 1;
//define date for title: EDIT this to create the time-format you need
$now_date = DATE('m-d-Y H:i');
//define title for .doc or .xls file: EDIT this if you want
$title = "Dump For Table $DB_TBLName from Database $DB_DBName on $now_date";
/*

Leave the connection info below as it is:
just edit the above.

(Editing of code past this point recommended only for advanced users.)
*/
//create MySQL connection
$Connect = @MYSQL_CONNECT($DB_Server, $DB_Username, $DB_Password)
     or DIE("Couldn't connect to MySQL:<br>" . MYSQL_ERROR() . "<br>" . MYSQL_ERRNO());
//select database
$Db = @MYSQL_SELECT_DB($DB_DBName, $Connect)
     or DIE("Couldn't select database:<br>" . MYSQL_ERROR(). "<br>" . MYSQL_ERRNO());
//execute query
$result = @MYSQL_QUERY($sql,$Connect)
     or DIE("Couldn't execute query:<br>" . MYSQL_ERROR(). "<br>" . MYSQL_ERRNO());

//if this parameter is included ($w=1), file returned will be in word format ('.doc')
//if parameter is not included, file returned will be in excel format ('.xls')
IF (ISSET($w) && ($w==1))
{
     $file_type = "msword";
     $file_ending = "doc";
}ELSE {
     $file_type = "vnd.ms-excel";
     $file_ending = "xls";
}
//header info for browser: determines file type ('.doc' or '.xls')
HEADER("Content-Type: application/$file_type");
HEADER("Content-Disposition: attachment; filename=database_dump.$file_ending");
HEADER("Pragma: no-cache");
HEADER("Expires: 0");

/*    Start of Formatting for Word or Excel    */

IF (ISSET($w) && ($w==1)) //check for $w again
{
     /*    FORMATTING FOR WORD DOCUMENTS ('.doc')   */
     //create title with timestamp:
     IF ($Use_Title == 1)
     {
         ECHO("$title\n\n");
     }
     //define separator (defines columns in excel & tabs in word)
     $sep = "\n"; //new line character

     WHILE($row = MYSQL_FETCH_ROW($result))
     {
         //set_time_limit(60); // HaRa
         $schema_insert = "";
         FOR($j=0; $j<mysql_num_fields($result);$j++)
         {
         //define field names
         $field_name = MYSQL_FIELD_NAME($result,$j);
         //will show name of fields
         $schema_insert .= "$field_name:\t";
             IF(!ISSET($row[$j])) {
                 $schema_insert .= "NULL".$sep;
                 }
             ELSEIF ($row[$j] != "") {
                 $schema_insert .= "$row[$j]".$sep;
                 }
             ELSE {
                 $schema_insert .= "".$sep;
                 }
         }
         $schema_insert = STR_REPLACE($sep."$", "", $schema_insert);
         $schema_insert .= "\t";
         PRINT(TRIM($schema_insert));
         //end of each mysql row
         //creates line to separate data from each MySQL table row
         PRINT "\n----------------------------------------------------\n";
     }
}ELSE{
     /*    FORMATTING FOR EXCEL DOCUMENTS ('.xls')   */
     //create title with timestamp:
     IF ($Use_Title == 1)
     {
         ECHO("$title\n");
     }
     //define separator (defines columns in excel & tabs in word)
     $sep = "\t"; //tabbed character

     //start of printing column names as names of MySQL fields
     FOR ($i = 0; $i < MYSQL_NUM_FIELDS($result); $i++)
     {
         ECHO MYSQL_FIELD_NAME($result,$i) . "\t";
     }
     PRINT("\n");
     //end of printing column names

     //start while loop to get data
     WHILE($row = MYSQL_FETCH_ROW($result))
     {
         //set_time_limit(60); // HaRa
         $schema_insert = "";
         FOR($j=0; $j<mysql_num_fields($result);$j++)
         {
             IF(!ISSET($row[$j]))
                 $schema_insert .= "NULL".$sep;
             ELSEIF ($row[$j] != "")
                 $schema_insert .= "$row[$j]".$sep;
             ELSE
                 $schema_insert .= "".$sep;
         }
         $schema_insert = STR_REPLACE($sep."$", "", $schema_insert);
         //following fix suggested by Josue (thanks, Josue!)
         //this corrects output in excel when table fields contain \n or \r
         //these two characters are now replaced with a space
         $schema_insert = PREG_REPLACE("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
         $schema_insert .= "\t";
         PRINT(TRIM($schema_insert));
         PRINT "\n";
     }
}
}

?>
IMPORTING FROM EXCEL INTO MySQL USING PHP
<table>
                    <form enctype="multipart/form-data" action="" method="post">
                      <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
                            <tr>
                            <td><h5><b>Select Standared</b></h5></td>
                            <td><select name="chap_sel_std" id="chap_sel_std">
                                                        <option>Select Standared</option>
                                                <?php
                                                    $exe_sel_std = mysql_query("SELECT * from s_standared");
                                                    while($r_sel_std = mysql_fetch_array($exe_sel_std)){
                                                        $sel_stdid = $r_sel_std['std_id'];
                                                        $sel_std = $r_sel_std['std'];?>

                                                        <option value="<?php echo $sel_stdid; ?>"><?php echo $sel_std;?></option>
                                                        <?php } ?>
                                </select></td>
                            </tr>
                            <tr>
                                <td><h5><b>Select Font</b></h5></td>
                                <td><select name="sel_f_gn_que">
                                    <option>Select Font</option>
                                        <?php
                                            $xf = mysql_query("SELECT * from s_font");
                                            while($rquef = mysql_fetch_array($xf)){
                                                $f_id = $rquef['f_id'];
                                                $f_name = $rquef['f_name'];  ?>
                                    <option value="<?php echo $f_id; ?>"><?php echo $f_name; }?>  </option>
                                </select></td>
                            </tr>
                            <tr>
                                <td><h5><b>Upload Question<h5><b></td>
                                <td>
                                    <input type="file" name="file" id="file" class="btn">
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td colspan="2"><input type="submit" class="btn btn-green big" name="add_que" value="Add Questions"></td>
                                <td><input type="submit" name="saveandexit" class="" value="Finish" onclick="close();"></td>
                            </tr>
                    </form>
                    </table>
                    </div>                   

    <?php

            $data = array();

    //$db =& DB::connect("mysql://root@localhost/names", array());
    //if (PEAR::isError($db)) { die($db->getMessage()); }
      //quetype    difficulty    standard    subject    chap    que    marks

    function add_person($quetype,$dif, $subject,$chap_name,$que,$marks)
    {
     global $data, $db;

     //$sth = $db->prepare( "INSERT INTO names VALUES( 0, ?, ?, ?, ? )" );
    // $db->execute( $sth, array( $first, $middle, $last, $email ) );

     $data []= array(
       'quetype' => $quetype, 
       'difficulty' => $dif,
       'subject' => $subject,
       'chap' => $chap_name,
       'que' => $que,
       //'ans' => $ans,
       'marks' => $marks

     );
    }

    if(!isset($_FILES['file']['tmp_name'])){
        echo "";
    }elseif($_FILES['file']['tmp_name'])
    {
     $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
     $rows = $dom->getElementsByTagName( 'Row' );
     $first_row = true;
     foreach ($rows as $row)
     {
       if ( !$first_row )
       {
         $quetype = "";
         $dif = "";
         $subject = "";
         $chap_name = "";
         $que = "";
         //$ans = "";
         $marks = "";

         $index = 1;
         $cells = $row->getElementsByTagName( 'Cell' );
         foreach( $cells as $cell )
         {
           $ind = $cell->getAttribute( 'Index' );
           if ( $ind != null ) $index = $ind;

           if ( $index == 1 ) $quetype = $cell->nodeValue;
           if ( $index == 2 ) $dif = $cell->nodeValue;
           if ( $index == 4 ) $subject = $cell->nodeValue;
           if ( $index == 6 ) $chap_name = $cell->nodeValue;
           if ( $index == 8) $que = $cell->nodeValue;
           //if ( $index == 9) $ans = $cell->nodeValue;
           if ( $index == 9) $marks = $cell->nodeValue;

           $index += 1;
         }
         add_person($quetype,$dif, $subject,$chap_name,$que,$marks);

         if(isset($_POST['add_que'])){    

                 $chap_sel_std = $_POST['chap_sel_std'];
                 echo $simquefnt = $_POST['sel_f_gn_que'];

                    //que_id    quetype_id    chap_id    sub_id    std_id    que    dif_id    marks    que_cdate
             //$chap_sel_std = $_POST['chap_sel_std']; //que_id    quetype_id    chap_id    sub_id    std_id    que    dif_id    marks    que_cdate
             mysql_query("INSERT INTO 
                          s_question
                          VALUES (null,'$quetype','$chap_name','$subject','$chap_sel_std','$que','NO IMAGE','$dif','$marks','$simquefnt','$current')");                                                        
    //         header("location:../admin/quetionaris.php#tabs-que"); 
         echo "Successfully Added";
          }
       }
       $first_row = false;
     }
    }
    ?>

Export Data in excel and then import from excel using PHP. DB is MySQL...

php mysql excel import export
Rectangle 27 1

1) Type Regedit in start menu

15.0 for Office 2013
 16.0 for Office 2016
 12.0 for Office 2010

create a DWORD(32bit) value and name it: ExtensionHardening. The possible values are:

0: Do not check the file name extension and
   the file type, and bypass the function of the warning message.

1: Check the file name extension and the file type.
   If they do not match, display the warning message.

2: Check the file name extension and the file
   type. If they do not match, do not open the file.

Use 1 as the value.

javascript - Export HTML Table to Excel- Doesn't Open in Office 2010 -...

javascript excel
Rectangle 27 1

Similar issue, my code dumps from a GridView to an XLS file using StringWriter, HTMLTextWriter and RenderControl.

Since our ASP.NET code runs on a company intranet we uninstalled the following updates across the company instead of going into 100s of user PCs and changing their settings.

This fixed our issue, and would also fix yours and others affected by these updates.

javascript - Export HTML Table to Excel- Doesn't Open in Office 2010 -...

javascript excel
Rectangle 27 0

$("#btnExport").click(function (e) {
    window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
    e.preventDefault();
});

Have a look here too. Next time, try widening your search criteria.

I don't understand 'data:application/vnd.ms-excel,' or how to change the name of the file that is downloaded

javascript - How do I export from an HTML table to an excel spreadshee...

javascript php html google-drive-sdk
Rectangle 27 0

Here's a function for doing this in Firefox with JavaScript, assuming the user has Excel installed on their machine:

var tableToExcel = (function() {
  var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
  return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
  }
})()

thanks its working just a minor problem its not exporting the css from the table to excel how could i do this in this function.Can u plz help me

Is there no way to get this to work with IE? Works great in FF but I really need a cross-browser solution.

This does not work for special characters. Characters such as i,,,, etc. are not being displayed properly.

Export dynamic html table to excel in javascript in firefox browser - ...

javascript excel firefox
Rectangle 27 0

As I mentioned in my comment, excelbuilderjs.com might work out for you. There are a couple of distinct downsides - one in that you can't simply turn an HTML table into an excel spreadsheet with colors and etc. It does require setup. But, in the case of where I work, we have a fairly standard color scheme and set of formatters that has been translated into a standalone set of instructions that is then included everywhere we need to construct a spreadsheet.

Based on a few simple examples of Knockout, you could probably just use the same data source to loop through and assign to EB - then just assign number formatting and date formatting as you would for an actual excel spreadsheet (i.e. $#,##0.00 for basic currency, m/d/yyyy for a basic date).

Side note - apparently some of my documentation didn't make it up. http://excelbuilderjs.com/cookbook/formatting.html is where you can get some basic info on formatting.

javascript - Knockout - Export html table with formatting - Stack Over...

javascript knockout.js export-to-excel
Rectangle 27 0

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>

javascript - HTML table export to Excel (XLS or CSV) - Stack Overflow

javascript html excel
Rectangle 27 0

The following code worked perfect for me with IE8+, Chrome and Firefox! Its the easiest way to Export HTML tables to Excel without using a blob, ActiveX-Elements or downloadify:

Just insert an empty Iframe in your HTML document:

<iframe id="txtArea1" style="display:none"></iframe>

Add the following function to your Script section and replace the table id:

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);
          }

and finally call the function:

<button id="btnExport" onclick="fnExcelReport();"> EXPORT </button>

or with JQuery:

$("#btnExport").click(function () {

            fnExcelReport();
        });

javascript - Is there any way to export html table into excel working ...

javascript jquery html excel table
Rectangle 27 0

What I did was, instead of adding code to write the tables to excel using response, use a javascript itself to send the tables over to excel. My initial thinking was to load and render the HTML table first, then once it was done give the user a button to select to export(hence the javascript function provided in the link below).

So if you have jquery or javascript that exports your table to excel and you have empty or null values in your cells of your table or nested tables you can add this javascript using a body onload tag to execute the function to add zeros or the function Shadow Wizard gave me to default to a value you set if it is null or empty.

<script language="JavaScript">
    function change() {
    var count='0';
    var TDs=document.getElementsByTagName('td')
    var length=TDs.length;

        i='0';
        while(i<length){
        if(TDs[i].innerHTML==''){
        count++;
        TDs[i].innerHTML = "0";
        }
        i++;
        }
    }
</script>

and for an example of exporting to excel using javascript then follow this link.

How to trigger a Javascript function that changes a html table before ...

javascript html asp-classic
Rectangle 27 0

Try set tag that have a buttons and a edit text with a class to indentify this doms ex.: Class='ignore'. After this clone this yout table and in table cloned remove all dom's that have class that you seted. After removed this doms pass the cloned table to function that will export to excel.

var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,', template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>', base64 = function(
                s) {
            return window.btoa(unescape(encodeURIComponent(s)))
        }, format = function(s, c) {
            return s.replace(/{(\w+)}/g, function(m, p) {
                return c[p];
            })
        }
        return function(table, name) {
            if (!table.nodeType)
                table = document.getElementById(table);
            var cln=table.cloneNode(true);
            var paras = cln.getElementsByClassName('ignore');

            while(paras[0]) {
                paras[0].parentNode.removeChild(paras[0]);
            }
            var ctx = {
                worksheet : name || 'Worksheet',
                table : cln.innerHTML
            }
            window.location.href = uri + base64(format(template, ctx))
        }
    })();
<input type="button"
        onclick="tableToExcel('testTable', 'W3C Example Table')"
        value="Export to Excel">
    <table id="testTable"
        summary="Code page support in different versions of MS Windows."
        rules="groups" frame="hsides" border="2">
        <caption>CODE-PAGE SUPPORT IN MICROSOFT WINDOWS</caption>
        <colgroup align="center"></colgroup>
        <colgroup align="left"></colgroup>
        <colgroup span="2" align="center"></colgroup>
        <colgroup span="3" align="center"></colgroup>
        <thead valign="top">
            <tr>
                <th>Code-Page<br>ID
                </th>
                <th>Name</th>
                <th>ACP</th>
                <th>OEMCP</th>
                <th>Windows<br>NT 3.1
                </th>
                <th>Windows<br>NT 3.51
                </th>
                <th>Windows<br>95
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1200</td>
                <td style="background-color: #00f; color: #fff">Unicode (BMP of
                    ISO/IEC-10646)</td>
                <td></td>
                <td></td>
                <td>X</td>
                <td>X</td>
                <td>*</td>
            </tr>
            <tr>
                <td>1250</td>
                <td style="font-weight: bold">Windows 3.1 Eastern European</td>
                <td>X</td>
                <td></td>
                <td>X</td>
                <td>X</td>
                <td>X</td>
            </tr>
            <tr>
                <td>1251</td>
                <td>Windows 3.1 Cyrillic</td>
                <td>X</td>
                <td></td>
                <td>X</td>
                <td>X</td>
                <td>X</td>
            </tr>
            <tr>
                <td>1252</td>
                <td>Windows 3.1 US (ANSI)</td>
                <td>X</td>
                <td></td>
                <td>X</td>
                <td>X</td>
                <td>X</td>
            </tr>
            <tr>
                <td>1253</td>
                <td>Windows 3.1 Greek</td>
                <td>X</td>
                <td></td>
                <td>X</td>
                <td>X</td>
                <td>X</td>
            </tr>
            <tr>
                <td>1254</td>
                <td>Windows 3.1 Turkish</td>
                <td>X</td>
                <td></td>
                <td>X</td>
                <td>X</td>
                <td>X</td>
            </tr>
            <tr>
                <td>1255</td>
                <td>Hebrew</td>
                <td>X</td>
                <td></td>
                <td></td>
                <td></td>
                <td>X</td>
            </tr>
            <tr>
                <td>1256</td>
                <td>Arabic</td>
                <td>X</td>
                <td></td>
                <td></td>
                <td></td>
                <td>X</td>
            </tr>
            <tr>
                <td>1257</td>
                <td>Baltic</td>
                <td>X</td>
                <td></td>
                <td></td>
                <td></td>
                <td>X</td>
            </tr>
            <tr>
                <td>1361</td>
                <td>Korean (Johab)</td>
                <td>X</td>
                <td></td>
                <td></td>
                <td>**</td>
                <td>X</td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <td>437</td>
                <td>MS-DOS United States</td>
                <td></td>
                <td>X</td>
                <td>X</td>
                <td>X</td>
                <td>X</td>
                <td class="ignore"><button>teste</button></td>
            </tr>
            <tr>
                <td>708</td>
                <td>Arabic (ASMO 708)</td>
                <td></td>
                <td>X</td>
                <td></td>
                <td></td>
                <td>X</td>
                <td class="ignore"><button>teste</button></td>
            </tr>
            <tr>
                <td>709</td>
                <td>Arabic (ASMO 449+, BCON V4)</td>
                <td></td>
                <td>X</td>
                <td></td>
                <td></td>
                <td>X</td>
                <td class="ignore"><button>teste</button></td>
            </tr>
            <tr>
                <td>710</td>
                <td>Arabic (Transparent Arabic)</td>
                <td></td>
                <td>X</td>
                <td></td>
                <td></td>
                <td>X</td>
                <td class="ignore"><button>teste</button></td>
            </tr>
            <tr>
                <td>720</td>
                <td>Arabic (Transparent ASMO)</td>
                <td></td>
                <td>X</td>
                <td></td>
                <td></td>
                <td>X</td>
                <td class="ignore"><button>teste</button></td>
            </tr>
        </tbody>
    </table>

i am all so using this in my application but it is not working in my system i am using ubuntu

there are some message in browser's console?

it works in one ubuntu system but not works in another system how can i find reason for that

To help you I need more information. What browser are you using? There are any message in browser console? Can you use browser's develop tools to debug the code and show me where are the error?

jquery - Exporting HTML table into excel using javascript - Stack Over...

javascript jquery html excel
Rectangle 27 0

just pass html string to htmlData variable, couple of problems there like its taking default name and while you open excel it says invalid format but data is in correct format.

javascript - Export Html table to excel file - getting incorrect forma...

javascript jsp table export-to-excel
Rectangle 27 0

You can use selectors from jQuery, clone of your table in memory then remove elements you don't want with appropriate selector.

javascript - Exclude Specific Columns when exporting data from HTML ta...

javascript php html excel export-to-excel