-1
我在C#中,但是当打开导出HTML表到Excel中脱颖而出它给我的错误,如:获取格式错误时导出HTML表格到Excel
我尝试了不同的扩展名与“办公室document.spreadsheetml.sheet“像.xlsx也仍然给出相同的错误。以下是我的C#代码:
//StrExport.Append(@"<html xmlns='urn:schemas-microsoft-com:office:Spreadsheet' xmlns:ss='urn:schemas-microsoft-com:office:Spreadsheet' xmlns='http://www.w3.org/TR/REC-html40'><head><title>Time</title>");
//StrExport.Append(@"<body lang=EN-US id=h1><div class=Section1>");
StrExport.Append(@"<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'><head><title>Time</title>");
StrExport.Append(@"<body lang=EN-US style='mso-element:header' id=h1><span style='mso--code:DATE'></span><div class=Section1>");
StrExport.Append("<DIV style='font-size:12px;'>");
StrExport.Append(dvInfo.InnerHtml);
StrExport.Append("</div></body></html>");
string strFile = "StudentInformations.xls";
// string strFile = "StudentInformations.xlsx";
string strcontentType = "application/excel";
//string strcontentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.ClearContent();
Response.ClearHeaders();
Response.BufferOutput = true;
Response.ContentType = strcontentType;
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFile);
Response.Write(StrExport.ToString());
Response.Flush();
Response.End();
请提供此消息的解决方案。
我也设置扩展名.xlsx,但是当设置xlsx excel没有打开。 –
@jitendrakumar _content_重要,而不是延伸。如何将扩展名设置为PNG;它神奇地使内容成为一个图像? –
@uwe Keim任何解决方案? –