2017-09-02 89 views

回答

-1

我是通過下面的代碼

wb.Worksheets.Add(dt); 
wb.Worksheet(1).Cell(5, 1).InsertTable(dt1); 
0

我認爲這是使用全爲您

using (XLWorkbook wb = new XLWorkbook()) 
       { 
        foreach (DataTable dt in ds.Tables) 
        { 
         //Add DataTable as Worksheet. 
         wb.Worksheets.Add(dt); 
        } 

        //Export the Excel file. 
        Response.Clear(); 
        Response.Buffer = true; 
        Response.Charset = ""; 
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; 
        Response.AddHeader("content-disposition", "attachment;filename=DataSet.xlsx"); 
        using (MemoryStream MyMemoryStream = new MemoryStream()) 
        { 
         wb.SaveAs(MyMemoryStream); 
         MyMemoryStream.WriteTo(Response.OutputStream); 
         Response.Flush(); 
         Response.End(); 
        } 
       } 
+0

,而要求是對所有表它將爲每個DataTable中的一個新的工作表同一張紙。 –

相關問題