xlsx文件的内容类型 [英] content type for xlsx file
本文介绍了xlsx文件的内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请给出在浏览器中打开xlsx文件的内容类型....
i alredy使用
application / vnd.openxmlformats -officedocument.spreadsheetml.sheet
但它没用...我无法打开xlsx文件......
请帮助我
解决方案
.xlsx文件的内容类型是:application /vnd.openxmlformats-officedocument.spreadsheetml.sheet
或者使用它:
Response.ContentType = < span class =code-string> application / vnd.ms-excel;
Response.AppendHeader( content-disposition, attachment; filename = myfile.xls);
对于Excel 2007及更高版本,MIME类型不同
Response.ContentType = 应用/应用/ vnd.openxmlformats-officedocument.spreadsheetml.sheet跨度>;
Response.AppendHeader( content-disposition, attachment; filename = myfile.xlsx);
或者,如果您正在尝试阅读该文件,请尝试以下方法:
DataSet objds = new DataSet();
string ConnStr = ;
if (FileExtension == 。xlsx )
{
ConnStr = Provider = Microsoft.ACE.OLEDB。 12.0;数据源= + FileName + ;扩展属性= \Excel 12.0 Xml; HDR =无; IMEX = 1\ ;跨度>;
}
else
{
ConnStr = Provider = Microsoft.Jet.OLEDB.4.0; Data Source = + FileName + ;扩展属性= \Excel 8.0; HDR =否; IMEX = 1 \;;
}
OleDbCommand selectCommand = new OleDbCommand();
OleDbConnection connection = new OleDbConnection();
OleDbDataAdapter adapter = new OleDbDataAdapter();
connection.ConnectionString = ConnStr;
string strSQL = SELECT * FROM [ Sheet 1中
跨度>;
if (connection.State!= ConnectionState.Open)
connection.Open();
OleDbCommand cmd = new OleDbCommand(strSQL,connection);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(objds);
connection.Close();
一切顺利。
--Amit
我也面临同样的问题,但我有一些交流发电机如果可以帮助你
(1)在stackoverflow上检查这一个
http://stackoverflow.com/questions/13724988/unable-to-generate-the-xlsx-file
2)总是使用
Response.ContentType =application / vnd.ms-excel;
只需将文件扩展名从xlsx更改为xls
并将其打开即可使用
pls give the content type for open a xlsx file in broowser....
i alredy used
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
but it is not useful...i cant open the xlsx file...
pls help me
解决方案
The content type for .xlsx files is:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Or use this:
Response.ContentType = "application/vnd.ms-excel"; Response.AppendHeader("content-disposition", "attachment; filename=myfile.xls");
For Excel 2007 and above the MIME type differs
Response.ContentType = "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AppendHeader("content-disposition", "attachment; filename=myfile.xlsx");
Or if you are trying to read the file then try this:
DataSet objds = new DataSet(); string ConnStr = ""; if (FileExtension == ".xlsx") { ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=No;IMEX=1\";"; } else { ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + ";Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\";"; } OleDbCommand selectCommand = new OleDbCommand(); OleDbConnection connection = new OleDbConnection(); OleDbDataAdapter adapter = new OleDbDataAdapter(); connection.ConnectionString = ConnStr; string strSQL = "SELECT * FROM [Sheet1
"; if (connection.State != ConnectionState.Open) connection.Open(); OleDbCommand cmd = new OleDbCommand(strSQL, connection); OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(objds); connection.Close();
All the best.
--Amit
hi,
I am also Facing Same Problem but I got some alternator If It can help u
(1)Check This One on stackoverflow
http://stackoverflow.com/questions/13724988/unable-to-generate-the-xlsx-file
2)always use
Response.ContentType = "application/vnd.ms-excel";
Just Change the File extention from xlsx to xls
and open it it will work
这篇关于xlsx文件的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文