使用Excel公式将HTML表导出到Excel

时间:2018-02-13 20:01:55

标签: javascript html excel

我已经使用下面提到的功能从HTML表中成功导出了excel

  handleExportExcelButton :function(){
    var self = this;
    $(".monthly-booking-sheets-report-details #bookingSheetsExcelReportButton").unbind('click');
    $(".monthly-booking-sheets-report-details #bookingSheetsExcelReportButton").click(function(e){
      var monthly_booking_sheets_report_table = document.getElementById('monthlyBookingSheetsReportTable');
      var monthly_booking_report_table_html = "<table border='2px'>";
      for(index = 0 ; index < monthly_booking_sheets_report_table.rows.length-1 ; index++)
      {
        monthly_booking_report_table_html += monthly_booking_sheets_report_table.rows[index].innerHTML+"</tr>";
      }
      monthly_booking_report_table_html += "</table>";
      var anchor_html_excel = document.createElement('a');
      anchor_html_excel.href = 'data:application/vnd.ms-excel' + ', ' + encodeURIComponent(monthly_booking_report_table_html);
      anchor_html_excel.download = 'Booking Report ' + self.start_date + '_' + self.end_date + '.xls';
      anchor_html_excel.click();
      e.preventDefault();
    })
  }

在导出之前,我在HTML表格列中的javascript中应用了一些计算,例如C = A - B

  A  |   B  | C
=================
1200 | 1000 | 200
1000 | 500  | 500 

这也是我实现的。 现在我想用这个公式导出excel,如果有人在excel中编辑A列或B列,那么C列应该显示各个值之间的新差异。那么我需要在我的javascript函数中进行哪些更改才能使其正常工作

  

注意:在实际的表格中,我的HTML表格中有20列

0 个答案:

没有答案
相关问题