Thanks for the sample. Changing to 64Bit did the trick.
I was building for 'Any CPU' but Visual Studio also ticked 'Prefer 32Bit', which I didn't realize.
Unticking it solved my memory problem.
I also want to add my headers as well.
I thought to be smart and use the 'normal' ImportDataTable() for the first row and use the optimized ImportDataTable() for the remaining rows.
But when using the ImportDataTable with importOnSave all other data seems to be cleared.
This is working:
worksheet.ImportDataTable(dataTable.AsEnumerable().Take(1).CopyToDataTable(), true, 1, 1, true);
workbook.SaveAs(newFileLocation, ExcelSaveType.SaveAsXLS);
I get my headers on my first row and my first data on the second row.
This is also working:
worksheet.ImportDataTable(dataTable.AsEnumerable().Skip(1).CopyToDataTable(), 3, 1, true);
workbook.SaveAs(newFileLocation, ExcelSaveType.SaveAsXLS);
The first two rows in the sheet are skipped and the first row from the datatable is skipped as well.
But when I want to combine these two, I always end up with the first two rows empty.
And it doesn't matter if I call ImportDataTable(.., true, 1, 1, true) before or after ImportDataTable(.., 3, 1, true)
Please assist one more time and explain to me how to get the headers in my file.