且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何导出excel(xls)文件而不显示警告消息

更新时间:2021-10-21 09:46:29

http://***.com/questions/10498375/how-do-i-save-an-excel-file-without-getting -a-format-warning-when-opening-using [ ^ ]





请参阅。
http://***.com/questions/10498375/how-do-i-save-an-excel-file-without-getting-a-format-warning-when-opening-using[^]


Refer this.


大家好,>


安装o2003PIA后立即安装O2003PIA和



浏览并添加此dll作为参考



Microsoft.Office.Interop.Excel.dll





添加这些命名空间







Hi all,

Just Install O2003PIA and

after installing o2003PIA browse and add this dll as reference

Microsoft.Office.Interop.Excel.dll


add these namespaces



using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Diagnostics;





和代码





and code

oleda1.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 message

Just click ctrl+alt+E in your project and select Managed Debugging assistance..

in that uncheck ContextSwitchDeadlock n OK

http://www.rocha.org/2010/05/contextswitchdeadlock-was-detected.html[^]

its working thanks for all your help.....