0

I have been trying to take a look at the approach in this article about writing to excel using OpenXML: https://blogs.msdn.microsoft.com/brian_jones/2010/06/22/writing-large-excel-files-with-the-open-xml-sdk/

I currently have a function that grabs all the rows from my database and stores it temporarily, and then i write each row one by one. With the SAX approach, both my original and replacement sheets are originally empty. What is the point of reading from the original sheet if there is nothing in there?

Is the SAX method only for excel->excel? The description makes it sound like it is viable for database->excel

Steven Hsu
  • 183
  • 1
  • 3
  • 15
  • Yeah, he could have written that article in a much better way. I've done what you are describing (database -> excel) and mostly used what his post describes. Create everything in the Excel document using the normal methods, but create the row and cell data using the StartWriteElement, WriteElement,, EndWriteElement approach. It's a pain to get it going at first, but eventually it works out. From what I read on the internet it should be faster (we never tested - we got it to work and said "great") – Flydog57 Nov 06 '18 at 17:22
  • If I remember correctly (it was two jobs ago), we wrote out a bunch of stuff using the standard object API. Then, we create the row and cell data using the XML API. Once that was finished, there was a bunch more stuff we added using the object API (for example, we added names that represented the columns on the sheet - until we knew how many rows there were, we didn't add the names). – Flydog57 Nov 06 '18 at 17:29
  • Have a look at my [answer here](https://stackoverflow.com/questions/32690851/export-big-amount-of-data-from-xlsx-outofmemoryexception/32787219#32787219). It gives an example which should be easy to convert to use data from the DB. – petelids Nov 06 '18 at 17:31

0 Answers0