by Mike Stephens
22. March 2007 14:29
So I recently had to write some code that would take some data and stick it in a pre-formatted (complicated) Excel spreadsheet.
I decided to use the XML format so I could easily do this without having to use the Excel COM object.
I had everything going good until I tried to open the file I was sending back through the browser twice in a row.
I kept getting an Workbook error and looking in the log i saw this
XML ERROR in Workbook Setting
REASON: Too many tags
FILE: C:\Documents and Settings\Mike\Local Settings\Temporary Internet Files\Content.IE5\90LEWOHS\Results_3_22_2007[3].xml
GROUP: Workbook
TAG: Worksheet
ATTRIB: Name
VALUE: MyWorksheetName
Well the problem ended up being because Excel saw the same filename twice in a row it was trying to open the dataset being fed to it within the same open workbook. Worksheet names must be unique within a Workbook so it was throwing the "Too many tags" error.
My solution to this was just just add a short unique id to the end of the file name so Excel wouldn't recognize it as the same file and presto! everything works as expected.