views:

533

answers:

2

I am trying to save a ListObject from a .NET 3.5 Excel 2007 VSTO Workbook to a new sheet (done) and save that new sheet to a new workbook (done) without that workbook requiring the VSTO customization file (!!!!!).

Has anyone had any luck with this? The only way I've had any success is just saving as a CSV file but that's not exactly acceptable in this case. I'd rather not save to a CSV just to copy back to a XLS file.

worksheet.SaveAs(saveDialog.FileName, Excel.XlFileFormat.xlOpenXMLWorkbook)

+3  A: 

If I understand correctly, you do not want the new workbook file to depend or load any VSTO customization?

Try this MSDN link to remove VSTO customization assemblies from workbooks.

Mike Regan
This was exactly what I needed. Thank you!
Chris Ridenour
+1  A: 

Ok this didn't end up working for me and here's why. The answer is still correct but I want to clarify for future users.

I have a ListObject I wanted to save in an external workbook using VSTO. Creating a new Worksheet and using SaveAs would rename the current Workbook to that and therefore I would have to close the entire workbook to remove the Customization.

What I should have done from the beginning is this:

Create the Worksheet and populate the ListObject on said Worksheet. Then use .Copy() with no parameters to create a new workbook. How do i find the workbook then though? I simply named the Worksheet Now.Ticks.ToString() and looked for any open workbook with the ActiveSheet.Name as Now.Ticks.ToString(). For this application, it doesn't need to be more in depth then that. I the saved THAT workbook and then closed it. Since the workbook was created with Copy it had no customizations on it and problem solved.

Chris Ridenour
sounds hard. why didn't you just do... Excel.Workbook wkbk = xlApp.Workbooks.Add(params); Excel.Worksheet wksht = wkbk.Worksheets.get_Item("Sheet1"); Insert code to populate ListObject onto wksht here... wkbk.Close(true);
Anonymous Type
I believe I tried that route first, but the resulting workbook had the VSTO requirement attached to it. I could be mistaken though.
Chris Ridenour
ok so do what i said then call the Workbook.RemoveCustomization method, on the wkbk object.
Anonymous Type