如何将xls升级到xlsx以避免在打开导出的excel文件时出错? [英] how to upgrade xls to xlsx to avoid the error while opening the exported excel file ?
本文介绍了如何将xls升级到xlsx以避免在打开导出的excel文件时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我以前对普通xls文件格式所做的事情。
This is what i used to do for normal xls file format .
Response.ClearHeaders();
string attachment = "attachment; filename=EndOfYearReport.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
//Response.ContentType = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.ContentType = "application/ms-excel";
Response.Write(strEndOfYear.ToString());
Response.End();
但在打开文件时出现错误: -
but while opening the file i get the error:-
"The file you are trying to open, '[filename]', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?" (Yes | No | Help)
因此尝试升级到新版xlsx ..
so tried to upgrade to new version xlsx ..
Response.ClearHeaders();
string attachment = "attachment; filename=EndOfYearReport.xlsx";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
//Response.ContentType = "application/ms-excel";
Response.Write(strEndOfYear.ToString());
Response.End();
但这次无法打开文件..
错误即将来临
but not able to open the file this time ..
error was coming
Error: excel cannot open the file .xlsx because the file format or file extension is not valid
请建议
Please suggest
推荐答案
只是更改文件名或扩展名并不意味着它可以工作:您还必须更改数据格式。
想一想:你可以将法拉利徽章放在福特嘉年华上,但这不会把它变成跑车!
您需要查看如何生成strEndOfYear
并生成xlsx兼容数据,以及使用正确的扩展名。
Just changing the file name or extension doesn't mean it will work: you have to change the data format as well.
Think about it: you can put Ferrari badges on a Ford Fiesta, but that isn't going to turn it into a sports car!
You need to look at how you producestrEndOfYear
and generate xlsx compatible data, as well as using the right extension.
这篇关于如何将xls升级到xlsx以避免在打开导出的excel文件时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文