62,238
社区成员




public void ExportToExcel()
{
System.IO.StringWriter sw = new System.IO.StringWriter();
string str="<?xml version=\"1.0\"?><?mso-application progid=\"Excel.Sheet\"?><Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:html=\"http://www.w3.org/TR/REC-html40\"><DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\"><Author>User</Author><LastAuthor>User</LastAuthor><Created>2012-10-10T11:18:43Z</Created> <Company>微软中国</Company><Version>11.5606</Version></DocumentProperties><ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\"><WindowHeight>9225</WindowHeight><WindowWidth>18180</WindowWidth><WindowTopX>240</WindowTopX> <WindowTopY>120</WindowTopY><ProtectStructure>False</ProtectStructure><ProtectWindows>False</ProtectWindows></ExcelWorkbook><Styles><Style ss:ID=\"Default\" ss:Name=\"Normal\"><Alignment ss:Vertical=\"Center\"/> <Borders/><Font ss:FontName=\"宋体\" x:CharSet=\"134\" ss:Size=\"12\"/> <Interior/> <NumberFormat/> <Protection/> </Style></Styles><Worksheet ss:Name=\"Sheet1\"><Table ss:ExpandedColumnCount=\"1\" ss:ExpandedRowCount=\"1\" x:FullColumns=\"1\" x:FullRows=\"1\" ss:DefaultColumnWidth=\"54\" ss:DefaultRowHeight=\"14.25\"> <Row> <Cell><Data ss:Type=\"String\">fdfd</Data></Cell> </Row> </Table><WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\"><Selected/><ProtectObjects>False</ProtectObjects><ProtectScenarios>False</ProtectScenarios></WorksheetOptions></Worksheet></Workbook>";
//string str = ConvertEntity().ToString();
//string str="<table><tr><td>品名</td><td>最高价格</td><td>最低价格</td><td>平均价格</td><td>计量单位</td><td>备注</td></tr><tr><td>青菜</td><td> </td><td> </td><td> </td><td>元/公斤</td><td> </td></tr></table>";
sw.Write(str);
sw.Close();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "GB2312";
//HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ".xlsx");
HttpContext.Current.Response.Write(sw);
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
HttpContext.Current.Response.End();
HttpContext.Current.Response.Close();
}