"Go" (C #) Import and export an Excel file using the Aspose.cells component

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.