c# - Exporting excel error : File you are trying to open FileName is in different format than specified extension -


I used the following code to export data from a dataset to file excel:

  Public Zero ExportRecords (System.Data.DataTable dt, string filename) {try {if (dt.Rows.Count> 0) {string path = AllinAudio_Temp; String Timestamp = Convert. Toasting (datetime.now); Timestamp = timestamp. Change ("", ""); Timestamp = timestamp. Change ("/", ""); Timestamp = timestamp Change (":", ""); FileName = fileName.Replace ("", ""); String filename = path + @ "\" + timestamp + "_" + filename + ".xls"; CarlosAge.XXLXMLR Workbook Book = New CarlosAge.XXLXMLR Workbook (); //// Add a worksheet with some data to CarlosAge.excelAclaimware. Worksheet sheet = book. Worksheets. Add ("Sheet1"); Worksheet style style = book. Style. Add ("Header Sky"); Style Font Bold = true; Worksheet style style = 1 book. Style. Add ("Headersitter 1"); style1.Font.Bold = True; Style1.Font.Color = "Red"; Worksheet line row; // sheet = Table. Add (); Line = sheet.ttable.day. Add (); Foreach (DataColumn column in dt.Column) {row.Cells.Add (new worksheet cell (column.ColumnName, "HeaderStyle")); } (Int i = 0; i & lt; dt.rows.Count; i ++) {line = sheet} Tables.Rows.Add (); For (int l = 0; l   

When the file is exported and we try to open it, then the message gives me:

 Enter image details here

I want the file only in xls format and I am also exxporting it in XML format.

But

When I tried with XLSX

 Enter the image details

The biggest gesture component The code that is being used to create ExcelXmlWriter appears to be written in Excel XML format, in which the file extension should be XML when you type the XLS If you use extensions, then excel the content Sector is expected to be in nature. When it fails to open the file as a classic excel file, then that option tries to find that excel XML works and warns you of the problem.

Solution: To use the file extension, change your output code instead of XML instead of XLS

(as previously mentioned in XLSX Is not.)

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -