views:

153

answers:

1

I'm trying to manipulate an Excel spreadsheet in C# using OpenXML. Specifically, I would like to access the currently active workbook that is open. I've only been able to find examples that open up an Excel document given a filename, such as:

    using (SpreadsheetDocument myWorkbook =
SpreadsheetDocument.Open(filename, true))

(Note: Using the 'Microsoft.Office.Interop.Excel' way, the active workbook is accessed like: Workbook activeWorkBook = (Workbook)Globals.ThisAddIn.Application.ActiveWorkbook;)

Has anyone done this?

A: 

I do not think that what you are trying to do is possible directly.

OpenXML will open a workbook based on the file name. It does not have any contact with Excel and therefore does not know which sheet is open, or if you have many open.

You may be able to do this by sending the file name as an input parameter to your program.

Shiraz Bhaiji
for now, this seems correct. I'll continue by using the old school 'Microsoft.Office.Interop.Excel' way of manipulating excel docs. Thanks!
dotNetkow