B
Buzz
Where to start...
I have a C# application that reads and writes data as xml. This data
is generally lists of numbers that the end user would like to
manipulate in Excel. So...
I have an Excel 2003 spreadsheet that uses an XML map (xsd file) to
place xml data in the cells I want. So this spreadsheet is really like
a template... I saved it with no data in it. Now I can open it and use
the Data->XML->Import/Export menus to open and save xml data.
This sucks for the end user because when they want to manipulate the
xml data, they need to open the template, use Data->XML->Import, change
the data, use Data->XML->Export. They basically need to be trained on
this process, and even so will tend to hit the normal Save button
(which saves the template) (yeah... make it read-only but then when you
close Excel even after exporting your xml it still asks if you want to
save.. how confusing). So I want to make this process easier.
So what I've done is, use VSTO to create a C# Excel Worksheet project.
When I create this I point it to my XML mapped template spreadsheet. I
then created a few nice buttons on the spreadsheet to Open Data and
Save Data. These buttons use the XMLMaps.Import and Export routines to
do the same thing as the Data->XML->Import/Export menus do... with nice
dialogs. The user can use these buttons instead of the menus. Ok.
But now I need to have a button in my actual C# application that can
launch this spreadsheet, and automatically import a particular xml
file. So I use the PIA's for Excel. First I use Workbooks.Open() to
open the template spreadsheet. Now I need to tell it to import the XML
file I want. This wouldn't work for me using any PIA function (and
anyway my template spreadsheet needs to know the full XML file path so
when the user saves it will save it to the right place). So to tell
the template which file, I have a textbox control on the spreadsheet.
textbox's text changes.
So that is how I open my spreadsheet and import my xml from my C#
application. Now the end user's life is getting easier.
(My question follows... but please comment on the way I am doing all
the above if you think there is a better way!)
Now the problem is, when I close the spreadsheet from within my C#
application, I see the EXCEL.EXE process remains in Task Manager's
process list. I KNOW, I KNOW... there are postings all over the web on
how to avoid this. I've done them... using Marshal.ReleaseComObject(),
setting to null, workbook.Close(), yourExcelApp.Quit(), GC.Collect(),
GC.WaitForPendingFinalizers(). But for some reason, these don't work
for a VSTO C# spreadsheet. And they work for a normal spredsheet...
but not for a VSTO create spreadsheet.
Here is a quick test to prove my point:
1) Create a new VSTO Excel C# spreadsheet project (choose new
speadsheet to keep it simple). Build it... and now you have arguably
the dumbest possibly VSTO spreadsheet.
2) Create a simple Windows C# application that uses Excel PIA's.
3) Make a button to call the Workbook.Open() routine to open the VSTO
spreadsheet you just created.
4) Make a button to close the spreadsheet... calling
yourExcelApp.Quit(). Go ahead and do all the
Marshal.ReleaseComObject() and GC crap if you want.
5) Watch the processes sorted by name. Push Open and see EXCEL.EXE,
push Close and it is still there. Hmmm.
6) As a sanity check, create a regular plain jane spreadsheet just by
using Excel. Try using this app to Open and Close it. EXCEL.EXE in
the processes comes and goes as expected.
So why does the VSTO spreadsheet EXCEL.EXE process linger?
Thanks for any help anyone can offer.
Buzz
I have a C# application that reads and writes data as xml. This data
is generally lists of numbers that the end user would like to
manipulate in Excel. So...
I have an Excel 2003 spreadsheet that uses an XML map (xsd file) to
place xml data in the cells I want. So this spreadsheet is really like
a template... I saved it with no data in it. Now I can open it and use
the Data->XML->Import/Export menus to open and save xml data.
This sucks for the end user because when they want to manipulate the
xml data, they need to open the template, use Data->XML->Import, change
the data, use Data->XML->Export. They basically need to be trained on
this process, and even so will tend to hit the normal Save button
(which saves the template) (yeah... make it read-only but then when you
close Excel even after exporting your xml it still asks if you want to
save.. how confusing). So I want to make this process easier.
So what I've done is, use VSTO to create a C# Excel Worksheet project.
When I create this I point it to my XML mapped template spreadsheet. I
then created a few nice buttons on the spreadsheet to Open Data and
Save Data. These buttons use the XMLMaps.Import and Export routines to
do the same thing as the Data->XML->Import/Export menus do... with nice
dialogs. The user can use these buttons instead of the menus. Ok.
But now I need to have a button in my actual C# application that can
launch this spreadsheet, and automatically import a particular xml
file. So I use the PIA's for Excel. First I use Workbooks.Open() to
open the template spreadsheet. Now I need to tell it to import the XML
file I want. This wouldn't work for me using any PIA function (and
anyway my template spreadsheet needs to know the full XML file path so
when the user saves it will save it to the right place). So to tell
the template which file, I have a textbox control on the spreadsheet.
And in the template's VSTO C# code, I import the xml data when thisFrom my C# application, I set the text of this to the XML data path.
textbox's text changes.
So that is how I open my spreadsheet and import my xml from my C#
application. Now the end user's life is getting easier.
(My question follows... but please comment on the way I am doing all
the above if you think there is a better way!)
Now the problem is, when I close the spreadsheet from within my C#
application, I see the EXCEL.EXE process remains in Task Manager's
process list. I KNOW, I KNOW... there are postings all over the web on
how to avoid this. I've done them... using Marshal.ReleaseComObject(),
setting to null, workbook.Close(), yourExcelApp.Quit(), GC.Collect(),
GC.WaitForPendingFinalizers(). But for some reason, these don't work
for a VSTO C# spreadsheet. And they work for a normal spredsheet...
but not for a VSTO create spreadsheet.
Here is a quick test to prove my point:
1) Create a new VSTO Excel C# spreadsheet project (choose new
speadsheet to keep it simple). Build it... and now you have arguably
the dumbest possibly VSTO spreadsheet.
2) Create a simple Windows C# application that uses Excel PIA's.
3) Make a button to call the Workbook.Open() routine to open the VSTO
spreadsheet you just created.
4) Make a button to close the spreadsheet... calling
yourExcelApp.Quit(). Go ahead and do all the
Marshal.ReleaseComObject() and GC crap if you want.
5) Watch the processes sorted by name. Push Open and see EXCEL.EXE,
push Close and it is still there. Hmmm.
6) As a sanity check, create a regular plain jane spreadsheet just by
using Excel. Try using this app to Open and Close it. EXCEL.EXE in
the processes comes and goes as expected.
So why does the VSTO spreadsheet EXCEL.EXE process linger?
Thanks for any help anyone can offer.
Buzz