I' m trying to export 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);
The connection string is
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AA\Desktop\work10.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";
I' m trying to export 100 rows to xlsx file. When I try to open the excel file, I' m getting
'Excel can not open the test.xlsx because file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file'
error.
After changing .xlsx extension to .xls, file is opening.
But xlsx option must be worked without changing extension.
Microsoft Access Database Engine 2010 version and Office Professional Plus 2013 is installed at the computer.
How can I solve this problem?