An alternative to using a StringBuilder to hold the entire spreadsheet is to write straight out to a textfile - see
How to: Write to a Text File (C# Programming Guide) | Microsoft Docs[
^]. You can use a StringBuilder for each row before you write it to the file (which will help to speed it up). You should use
sb.Clear();
for each loop.
If you don't want to make that much of a change to your existing code (which we can't run - there are too many declarations etc missing), then surround the dataread with a loop that only handles, say, 1000 rows...
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= rowcount; i += 1000)
{
sb = new StringBuilder();
}