CSV to Excel Memory Consumption


#1

We have to be able to convert at least 1 Million rows x 50 cols from csv to excel worksheet. I have tried this and the memory usage goes up to many GB even when I am streaming the file. How can I make sure I actually stream the file and do not use so much memory?

The code I use is below

            FileStream fstream = new FileStream(tempCsvPath, FileMode.Open);

            LoadOptions csvLoadOptions = new LoadOptions(LoadFormat.CSV);

            Workbook csvWorkbook = new Workbook(fstream, csvLoadOptions);

#2

@gangchoi9

Thanks for using Aspose APIs.

Please use MemorySetting.MemoryPreference for your needs. Here is the code to load your CSV file and then convert it to XLSX format.

C#

LoadOptions opts = new LoadOptions(LoadFormat.CSV);
opts.MemorySetting = MemorySetting.MemoryPreference;

Workbook wb = new Workbook("yourCSV.csv", opts);
wb.Save("output.xlsx");