Friday, June 29, 2018
Write data to an Excel worksheet with C fast
Write data to an Excel worksheet with C fast
Source: http://www.clear-lines.com/blog/post/Write-data-to-an-Excel-worksheet-with-C-fast.aspx
The current project I am working on requires writing large amount of data to Excel worksheets. In this type of situation, I create an array with all the data I want to write, and set the value of the entire target range at once. I know from experience that this method is much faster than writing cells one by one, but I was curious about how much faster, so I wrote a little test, writing larger and larger chunks of data and measuring the speed of both methods:
private static void WriteArray(int rows, int columns, Worksheet worksheet){var data = new object[rows, columns];for (var row = 1; row <= rows; row++){for (var column = 1; column <= columns; column++){data[row - 1, column - 1] = "Test";link download