Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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,
Posted
Updated 2-Apr-13 2:47am
v4
Comments
phil.o 2-Apr-13 7:14am    
When you write : convert it to xls, do you make an actual conversion, or do you just change the extension ?
GaviGunda 2-Apr-13 8:50am    
Hi phil.o,
thanks for replay,I need full conversion, in both cases ie by actual conversion or by changing extension I am getting same warning message, So which 1 would u prefer to get xls without warning/error message,n how to do that.. plz help
phil.o 2-Apr-13 8:56am    
I don't prefer any, I was just driving your attention to the fact that changing a file's extension does not, in any way, change the format of the file.
As to the conversion, I have no clue on how to do it ; and I don't have time to google for you the way to achieve it. It's up to you to do this research.

The error message is pretty straightforward : you have a file with a given extension that does not correspond to the actual format of the file.
GaviGunda 2-Apr-13 8:58am    
OK thanks.. I got this link regarding that error

http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx

but unable to resolve..

in this link they mentioned some key and value but where to Include not getting??
Maciej Los 2-Apr-13 8:59am    
Code! We need to see your code!!!
Please use "Improve question" widget to update your question.

Hi all,

Just Install O2003PIA and

after installing o2003PIA browse and add this dll as reference

Microsoft.Office.Interop.Excel.dll


add these namespaces



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


and code

C#
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++;
                                    }

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.....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900