【问题标题】:Exported Excel from HTML table not opening in google sheets从 HTML 表中导出的 Excel 未在 Google 工作表中打开
【发布时间】:2018-02-28 00:01:49
【问题描述】:

我已经编写了 javascript 函数来将 HTML 表格转换为 Excel(完成),但是当我尝试在谷歌表格中打开我导出的 excel 时,它给了我类似这样的响应

我需要在 prototype JS function 中进行哪些更改才能解决此问题

  handleexportExcel :function(){
    var self = this;
    $(".monthly-payments-report-details #paymentExcelReport").unbind('click');
    $(".monthly-payments-report-details #paymentExcelReport").click(function(e){
      var payment_report_table_html = "<table border='2px'>";
      var monthly_payment_report_table = document.getElementById('monthlyPaymentReportTable');
      for(index = 0 ; index < monthly_payment_report_table.rows.length-1 ; index++)
      {
        payment_report_table_html += monthly_payment_report_table.rows[index].innerHTML+"</tr>";
      }
      payment_report_table_html += "</table>";
      var anchor_html_excel = document.createElement('a');
      anchor_html_excel.href = 'data:application/vnd.ms-excel' + ', ' + encodeURIComponent(payment_report_table_html);
      anchor_html_excel.download = 'Payment Report_' + self.start_date + '_' + self.end_date + '.xls';
      anchor_html_excel.click();
    })
  }

【问题讨论】:

    标签: javascript html excel google-sheets


    【解决方案1】:

    Google 表格会准确显示您导出的内容。

    仅仅因为 Excel 决定将 HTML 表格显示为工作表,并不意味着 GS 开发人员有义务包含该功能。

    如果要导出实际的 Excel 文件,请在 js 中使用不同的方法。

    【讨论】:

    • 感谢您的建议。请您分享哪种方法定义可以解决我的问题
    • 您将需要使用一种可以输出“真实”Excel 文件的方法,但是推荐工具/库的请求在 SO 上是题外话(而且我没有这样做的经验)。像github.com/SheetJS/js-xlsx 这样的东西可能对你有用。
    猜你喜欢
    • 2017-03-22
    • 2016-04-24
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多