Hi all,
I am looking for a fastest way for exporting datagridview content to Excel-2010.I
have already done by converting first dataset to xml then to .xlsx.But finding some
issues in this solution.Is this method is fastest?Or any other method?
I will give the code what I have already done
idssTableDataSet.WriteXml("D:\\Customers.xml");
Microsoft.Office.Interop.Excel.Application APexcel = null;
Microsoft.Office.Interop.Excel.Workbook MyBook = null;
Microsoft.Office.Interop.Excel.Worksheet MySheet = null;
APexcel = new Microsoft.Office.Interop.Excel.Application();
APexcel.Visible = false;
MyBook = APexcel.Workbooks.Open("D:\\Customers.xml", Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
MySheet = (Microsoft.Office.Interop.Excel.Worksheet)MyBook.ActiveSheet;
MyBook.SaveAs("D:\\Customers.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, false, false, null, null, null);
After saving the .xlsx file it is showing an error that "Excel cannot open the file because the file format or extension is not valid.Verify that the file has not been corrupted and the file extension matches the format of the file" when I am opening the .xlsx file.Please help me.
Thanks in advance