Home > Net >  Webform export excel
Webform export excel

Time:12-22

Using npoi export excel, is it have any resources to release, after the execution of the error, and the Exception capture failure, tip: because the code has been optimized, or the machine frame is located on the call stack, unable to calculate the value of the expression,
 
HttpResponse Response=HttpContext. Current. The Response;
The Response. The Clear ();
The Response. The ContentType="application/VND. Openxmlformats - officedocument. Spreadsheetml. Sheet".
Response. AddHeader (" the Content - Disposition ", the string. Format (" attachment; Filename={0} ", excelName + ". XLSX "));

XSSFWorkbook workbook=new XSSFWorkbook ();
ISheet sheet1=workbook. CreateSheet (" sheet1 ");

//add the first line of the head to sheet1 title
IRow row1=sheet1. CreateRow (0);
for (int i=0; I & lt; DgDataGrid. Columns. The Count; I++)
{
Row1. CreateCell (I). SetCellValue (dgDataGrid. Columns [I] the HeaderText);
}
for (int i=0; I & lt; DgDataGrid. Items. The Count; I++)
{
NPOI. SS. UserModel. IRow rowtemp=sheet1. CreateRow (I + 1);
For (int j=0; J & lt; DgDataGrid. Columns. The Count; J++)
{
Rowtemp. CreateCell (j) SetCellValue (dgDataGrid. Items [I] Cells [j]. Journal of Text).
}
}

//write to the client
System. IO. MemoryStream ms=new System. IO. MemoryStream ();
Workbook. Write (ms);
The Response. BinaryWrite (Ms. ToArray ());
The Response. The Flush ();
The Response. The End ();//step into The Times wrong
  • Related