I need to ask how to create multiple new excel spreadsheet files problematically from an arraylist on the c# backgroundworker thread
currently I have a function that goes through a for each loop and :
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
then it disposes of the excel object
by doing this in a backgroundworker thread, it causes all sorts of problems from blank worksheets to data split on multiple worksheets.
Would appreciate any feedback on how to go about this, basically want to show a marquee progressbar when the operation is being done, so I need to use the backgroundworker thread else if I don't use threading, the progressbar does not move, cause of all processing on the main GUI thread
Thanks to Dave,
I managed to use Excel OLEDB to write using background worker thread then go back with interop to format (which is way less cpu/process intensive !)
My next dilemma is how to determine which Office 2010 32/64 bit version is installed then adjust the cpu build on start up to that version so the Ace OLEDB driver does not fail !
Considering the Excel object model is not at all thread-safe I would say that you cannot do what you want. Excel doesn't work from background threads. It's on the main thread or you run into the problems you've described.
Though, I've only done interop with Excel once.
I cant believe I'm saying this, but you could put a Application.DoEvents in the ProgressBar update code. Just be very very careful and not give the user anything to click on during this operation. If you don't, those buttons or whatnot will still work if they are enabled! Don't get caught in a re-entrancy trap where a button click kicks off long running work and you didn't disable the button.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)