本文介绍了如何导出excel(xls)文件而不显示警告消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 任何1可以帮我导出xls文件而不收到警告信息, 我能够上传xlsx文件并能够将其转换为xls但无法打开xls文件而没有警告我收到,文件格式不支持,可以任何1请给出解决方案... 错误消息: 您要打开的文件''someFileName.xls采用不同的格式比文件扩展名指定的。在打开文件之前验证文件是否已损坏并且来自受信任的来源。您要立即打开文件吗? 非常感谢,Hi all,Can any 1 please help me to export xls file without getting warning message,I am able to upload xlsx file and able to convert it to xls but unable to open xls file without warning I am getting, file format is not supporting, can any 1 please give the soln...error msg:"The file you are trying to open, ''someFileName.xls, is in a different format than specified by the file extension. Verify that file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"Thanks a lot in advance,推荐答案using Microsoft.Office.Core;using Excel = Microsoft.Office.Interop.Excel;using System.Reflection;using System.Diagnostics; 和代码and codeoleda1.Fill(ds); Microsoft.Office.Interop.Excel.Application oAppln; //declaring work book Microsoft.Office.Interop.Excel.Workbook oWorkBook; //declaring worksheet Microsoft.Office.Interop.Excel.Worksheet oWorkSheet; oAppln = new Microsoft.Office.Interop.Excel.Application(); oWorkBook = (Microsoft.Office.Interop.Excel.Workbook)(oAppln.Workbooks.Add(true)); //oWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWorkBook.ActiveSheet; int i2 = 0; foreach (DataTable table in ds.Tables) { //oWorkSheet = new Microsoft.Office.Interop.Excel.Worksheet(); oWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)(oWorkBook.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing)); if (i2 == 0) { oWorkSheet.Name = "first"; } else { oWorkSheet.Name = "second"; } oWorkSheet.Activate(); //oWorkBook.Worksheets.Add(null, null, 1, null); //DataTable table = DATASETNAME.Tables[0]; int ColumnIndex = 0; foreach (DataColumn col in table.Columns) { ColumnIndex++; oWorkSheet.Cells[1, ColumnIndex] = col.ColumnName; } int rowIndex = 0; foreach (DataRow row in table.Rows) { rowIndex++; ColumnIndex = 0; foreach (DataColumn col in table.Columns) { ColumnIndex++; oWorkSheet.Cells[rowIndex + 1, ColumnIndex] = row[col.ColumnName].ToString(); } } // Worksheet worksheet = (Worksheet)oAppln.ActiveSheet; //worksheet.Activate(); i2++; } 如果你得到ContextSwitchDeadlock警告信息 只需点击ctrl + alt + E in您的项目并选择托管调试帮助.. 取消选中ContextSwitchDeadlock n确定 http://www.rocha.org/2010/05/contextswitchdeadlock-was-detected.html [ ^ ] 工作谢谢你的帮助......if u get ContextSwitchDeadlock warning messageJust click ctrl+alt+E in your project and select Managed Debugging assistance..in that uncheck ContextSwitchDeadlock n OKhttp://www.rocha.org/2010/05/contextswitchdeadlock-was-detected.html[^]its working thanks for all your help..... 这篇关于如何导出excel(xls)文件而不显示警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 05:52
查看更多