Export GridView to multiple Excel sheet

后端 未结 4 676
北荒
北荒 2020-11-29 12:34

I have two Gridview in my Web application.I need ,while clicking the (ExcelExpot) button the values to be Export in Excel Accordingly Sheet1 and Sheet2.

  pr         


        
4条回答
  •  离开以前
    2020-11-29 13:04

    Rather than using some 3rd party library or the Excel automation (with it's added overhead) you can just use ADO.NET.

    http://support.microsoft.com/kb/316934#10

    You would simply use the T-SQL your used to with OleDbCommand objects.

    CREATE TABLE Sheet1 (id INT, name char(255))
    CREATE TABLE Sheet2 (id INT, name char(255))
    // for inserts use a parameterized command with ?'s
    INSERT INTO Sheet1 (id, name) VALUES(?, ?)
    INSERT INTO Sheet1 (id, name) VALUES(?, ?)
    

    You'd create your temp excel file using the Path.GetTempFileName and output it, after which you can delete the temp file.

提交回复
热议问题