Export an Excel file with the extension .xlsx

I am trying to export an xlsx file with these codes:

DataTable dataTable= new DataTable(tableName);
OleDbDataAdapter adapter = new OleDbDataAdapter(select, accessConnection);    
adapter.FillSchema(dataTable, SchemaType.Source);

foreach (DataRow result in dtResult.Rows)
{
     DataRow newRow = dataTable.NewRow();
     foreach (DataRow drAssign in dtAssignment.Rows)
     {
          newRow[drAssign["Destination"].ToString()] = result[drAssign["Source"].ToString()];
     }
     dataTable.Rows.Add(newRow);
}

adapter.Update(dataTable);

Connection string

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AA\Desktop\work10.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";

I am trying to export 100 lines to an xlsx file. When I try to open an excel file, I get

'Excel cannot open the test.xlsx file because the file format or file extension is invalid. Verify that the file has not been corrupted and that the file extension matches the file format '

mistake.

After changing the extension .xlsx to .xls, the file opens.

But the xlsx parameter should work without changing the extension.

Microsoft Access Database Engine 2010 and Office Professional Plus 2013 are installed on the computer.

How can I solve this problem?

+4
1

, OLEDB , XML, https://support.microsoft.com/en-us/kb/928979

XML, ClosedXml Excel.Interop.

+1

Source: https://habr.com/ru/post/1625979/


All Articles