DataGrid Export Excel

zhaozj2021-02-16  58

Public void DataGridToExcell ()

{

String filesname = "dd.xls";

SpreadsheetClass Xlssheet = new spreadsheetclass (); // Installation of a table in Execl

INT TEMPCOLUMN = 0;

Foreach (System.Web.ui.WebControls.DataGridColumn OITEM in this.mydatagrid.columns) // Traversing each column of the DataGrid, add a header

{

Xlssheet.Activesheet.cells [1, TempColumn 1] = OITEM.HEADERTEXT; // Add a header

TempColumn ;

}

For (int i = 1; i <= this.mydatagrid.Items.count; i ) // Traversing every line in DataGrid,

{

For (int J = 1; j <= this.mydataGrid.Items [i-1] .cells.count; J )

{

Xlssheet.Activeesheet.cells [i 1, j] = this.mydataGrid.Items [i-1] .cells [j-1] .TEXT;

// Do not have a negative value for the EXCEL table that has just defined

}

}

Xlssheet.Activeesheet.export ("D: //" FilesName, Owc.shetexportActionNum.SsexportActionnone); // Execl Table Export

}

转载请注明原文地址:https://www.9cbs.com/read-16548.html

New Post(0)