2016-06-10 3 views
-1
나는 C#을하지만 경우 개방에서 Excel로 HTML 테이블을 수출하고

에 HTML 테이블을 내보내는이 같이 나에게 오류를주고있다 엑셀 때 : enter image description here얻기 형식 오류가 엑셀

나는 "와 다른 확장을 시도 office 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(); 

이 메시지를 해결하십시오.

답변

1

예상됩니다. HTML을 내보내고 있지만 .xlsx라고합니다. Excel은 해석하기에 충분히 영리하지만이 경고를 받게됩니다.

경고가 없으므로 즉시 사용할 수있는 라이브러리를 사용하여 네이티브 .xlsx 형식으로 출력을 빌드해야합니다.

+0

또한 확장명을 .xlsx로 설정했지만 xlsx가 설정되지 않으면 Excel이 열리지 않습니다. –

+0

@jitendrakumar _content_는 확장 물이 아니라 중요한 사항입니다. PNG로 확장을 설정하는 방법; 마술처럼 내용을 이미지로 만드나요? –

+0

@uwe Keim 모든 솔루션 ?? –