Fares Ayyad

Fares Ayyad

  • NA
  • 235
  • 74.6k

Exporting HTML table to Excel in aspx page with arabic conte

Oct 11 2016 7:32 AM

I wrote code using Ajax/C# that will append data with jQuery to HTML table ,this is the table headers:


  1. table id='tblUsers' class='table table-striped table-condensed table-hover table-bordered table-responsive' >        
  2.              <tr>  
  3.                    <th>Customer ID</th>  
  4.                    <th>Customer Name</th>  
  5.                    <th>File #</th>  
  6.                    <th>Territory</th>  
  7.                    <th>Start Date</th>  
  8.                    <th>Goods Desc</th>  
  9.                    <th>Custom Declaration</th>  
  10.                    <th>Quantity</th>  
  11.                    <th>Weight</th>  
  12.                    <th>Volumetric Weight</th>  
  13.                    <th>Mortage Amount</th>  
  14.                    <th>Invoice#</th>  
  15.                    <th>Invoice Amount</th>  
  16.              </tr>  
  17.      </table>      
 
and this is the Ajax Call:
 
 
  1. $.ajax({  
  2.                        url: "WebService.asmx/showResult",  
  3.                        type: "post",  
  4.                        data: JSON.stringify({  
  5.                            "dateFrom": $('#txtDateFrom').val(),  
  6.                            "dateTo": $('#txtDateTo').val(),  
  7.                            "ddlType": $("#ddlType").children("option").filter(":selected").val(),  
  8.                            "ddlTer": $("#ddlTer").children("option").filter(":selected").val(),  
  9.                            "ddlFilter": $("#filter").children("option").filter(":selected").val()  
  10.                        }), // parameters  
  11.                        beforeSend: function () {  
  12.                            $('#loader').html('<img src="Images/loading.gif" />');  
  13.   
  14.   
  15.                        },  
  16.   
  17.                        contentType: "application/json; charset=utf-8",  
  18.                        success: function (result) {  
  19.                            $('#loader').html('');  
  20.                            document.getElementById('filter').style.display = 'inherit';  
  21.                            document.getElementById('logo').style.display = 'none';  
  22.                            document.getElementById('exp').style.display = 'inherit';  
  23.                            //To delete the whole tr except the first one.  
  24.                            $("#tblUsers").find("tr:gt(0)").remove();  
  25.                            $('#tblUsers').append(JSON.stringify(result));  
  26.                            if ($("#ddlType").val() != 0) {  
  27.                                document.getElementById('filter').style.display = 'none';  
  28.   
  29.                            }  
  30.   
  31.                        },  
  32.                        error: function () {  
  33.                            alert('error');  
  34.                        }  
  35.   
  36.   
  37.                    });  
The WebMethod:
 
 
  1. var sp = db.divideTypes(dateFrom, dateTo, ddlFilter).ToList();  
  2.      foreach (var u in sp)  
  3.      {  
  4.            result += "<tr>";  
  5.   
  6.            result += "<td>" + u.custid + "</td>";  
  7.            result += "<td>" + u.custname + "</td>";  
  8.            result += "<td>" + u.depno + "</td>";  
  9.            result += "<td>" + u.Terr + "</td>";  
  10.            result += "<td>" + u.deidate + "</td>";  
  11.            result += "<td>" + u.gooddesc+ "</td>";  
  12.            result += "<td>" + u.custdec + "</td>";  
  13.            result += "<td>" + u.pkg + "</td>";  
  14.            result += "<td>" + u.wt + "</td>";  
  15.            result += "<td>" + u.vwt + "</td>";  
  16.            result += "<td>" + u.lcamt+ "</td>";  
  17.            result += "<td>" + u.invno + "</td>";  
  18.            result += "<td>" + u.invamt + "</td>";  
  19.            result += "<td></td>";  
  20.   
  21.            result += "</tr>";  
  22.      }  
 
 

i tried to read articles over the web to export excel table as excel file but using JQuery, http://wsnippets.com/export-html-table-data-excel-sheet-using-jquery/

Heading

and there's a lot of articles like this all of them failed because i want to render Arabic letters so the letters looks strange.

i notice that there's an article in stackOverflow:http://stackoverflow.com/questions/17988417/export-data-table-with-arabic-data-to-excel

that talk about a situation similar to mine, but really i don't know how to implement it.

 
 
 

Answers (4)