设计Excel并使用javascript

时间:2018-12-12 09:09:58

标签: javascript asp.net

我已经使用javascript创建了一个Excel文档,但是我打开了该文档,但我希望它不像excel文档那样打开/另存为PDF我已经尝试了多种方法,但是没有用,任何人都可以帮忙。 这是我使用的代码。

function exportToExcelPdf() {
  input_box = confirm("Експортирај во Microsoft Excel?");
  if (input_box == true) {
    var xlApp = new ActiveXObject("Excel.Application");

    xlApp.DisplayAlerts = false;
    var xlBook = xlApp.Workbooks.Add();
    xlBook.worksheets("Sheet1").activate;
    var XlSheet = xlBook.activeSheet;
    XlSheet.Name = "Sheet Name";

    var myRange = XlSheet.Range("A1:L1");
    myRange.merge();
    myRange.value = "Something Some Text";
    myRange.font.size = 14;
    myRange.font.bold = "true";
    myRange.HorizontalAlignment = -4108;
    myRange.interior.colorindex = "37";

    var myRange = XlSheet.Range("A3:L3");
    myRange.merge();
    myRange.value = "Something Some Text";
    myRange.font.size = 11;
    myRange.font.bold = "true";
    myRange.HorizontalAlignment = -4108;
    myRange.interior.colorindex = "37";


    var dt = document.getElementById('<%= GridView1.ClientID %>');
    for (var y = 1; y < dt.rows.length; y++)
    // detailsTable is the table where the content to be exported is
    {
      for (var x = 0; x < dt.rows(y).cells.length; x++) {
        XlSheet.Cells(y + 18, x + 1) = dt.rows(y).cells(x).innerText;
        XlSheet.Cells(y + 18, x + 1).HorizontalAlignment = -4108;
      }
    }


    //autofit the columns
    XlSheet.columns.autofit;

    xlApp.ActiveWindow.DisplayGridlines = false;

    // Make visible:   
    xlApp.visible = true;

    xlApp.DisplayAlerts = true;
    CollectGarbage();
    //xlApp.Quit();
  }
}

0 个答案:

没有答案