tôi có mã này để trích xuất một bảng vào máy tính trong một file .xls:Cách tạo tệp XLS thực trên asp.net C#?
// I have a string which contains HTML table codes, named as excelTable
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Disposition", String.Format("Attachment;Filename=file.xls",));
response.Buffer = true;
response.ContentEncoding = System.Text.Encoding.Default;
response.ContentType = "application/vnd.ms-excel";
response.Write(excelTable);
response.End();
Và tôi đã thấy rằng đây không phải là một tập tin .xls thực. Tôi có thể mở nó trong Notepad và xem mã bảng standart html của tôi.
Bây giờ tôi hiểu rằng việc xác định ContentType
là không đủ. Vậy tôi có thể làm gì khác để tạo tệp .xls hoặc .xlsx thuần túy? Hoặc tôi chắc chắn nên sử dụng Excel Thư viện như OpenXML, Interop, vv?
http://epplus.codeplex.com/ – AakashM