The Aspose.cells component can import and export Excel files without relying on Excel:
Import:
Public Static System.Data.DataTable readexcel (String strFileName) { new Workbook (); Book. Open (strFileName); = Book. worksheets[0]; = sheet. Cells; return cells. Exportdatatableasstring (0011true); }
Export:
Private Static voidExport<t> (ienumerable<t>data, HttpResponse response) {Workbook Workbook=NewWorkbook (); Worksheet sheet= (Worksheet) workbook. worksheets[0]; Propertyinfo[] PS=typeof(T). GetProperties (); varColindex ="A"; foreach(varPinchPS) {Sheet. Cells[colindex+1]. Putvalue (P.name); inti =2; foreach(varDinchdata) {Sheet. Cells[colindex+ i]. Putvalue (P.getvalue (D,NULL)); I++; } Colindex= ((Char) (colindex[0] +1)). ToString (); } response. Clear (); Response. Buffer=true; Response. Charset="Utf-8"; Response. Appendheader ("content-disposition","Attachment;filename=xxx.xls"); Response. ContentEncoding=System.Text.Encoding.UTF8; Response. ContentType="Application/ms-excel"; Response. BinaryWrite (workbook. Savetostream (). ToArray ()); Response. End (); }
Transferred from: http://blog.csdn.net/weiky626/article/details/7514637
"Go" (C #) Import and export an Excel file using the Aspose.cells component