none
Open and Read a Protected Excel 2007 Workbook from C# (I have the password) RRS feed

  • Question

  • Hey folks,

     

    I simply want to open an Excel Workbook, access the Worksheets and retrieve data from individual cells, rows or columns using a DLL -- Not an Excel-based solution, an external DLL called by a console app. 

     

    The data I retrieve will be used in a C# program that validates a batch process that produces .csv files, so I want this process to have as few human interactions as possible (read as, automated testing from an external script).

     

    The document is locked (I have the password) and I get errors using Open XML SDK (Invalid format), and I'm having a devil of a time trying to figure out how to open and read the elements I need.

     

    It seems the documentation assumes that you already know certain secrets, and yet there is no pointer to the secrets.  It's either badly organized or the information is not generally available.

     

    I have in mind, something like this:

     

    public string GetDataFromCell(int row, string column)

    {

    ExcelWorkbook wb = ExcelWorkbook.Open(fileName, password, readOnly)

    return wb.Sheets[0].Cell(row, column).Value.ToString();

    }

     

    Why does it have to be so hard?  Haven't you guys ever heard of abstraction?

     

    If Open XML isn't the way, please point me to where I need to be.  All the docs assume I want to manipulate Excel from within Excel; I don't.

     

    Thanks - Jon

     

    Wednesday, July 2, 2008 7:17 PM

All replies

  • I don't have an answer for you but I too REALLY wish they would get it together in the Open XML Format SDK for the excel 2007 parts. Would it completely unravel the universe to have a simple way to access a cell or row? As it stands the majority of the examples I find STILL reference the System.IO.Packaging that the Open XML format SDK is supposed to be getting away from (http://msdn.microsoft.com/en-us/library/bb332058.aspx). It is almost shameful at this point that you still have to go through all that.

      If they HAVE added a way to more easily get the value of a cell PLEASE someone post it.

    Monday, July 7, 2008 9:53 AM
  • As Undev pointed out to me in another thread, the SpreadSheetML stuff has yet to be included. Hopefully we will have some good stuff to play with in the next release, hurry devs!!! =)

     

    As is I used the System.IO.Packaging example I referenced above. It's ugly and it feels dirty, but it works.

    Monday, July 7, 2008 5:45 PM
  • Hello Jonathan,

    Did you find a way to read data from password-protected spreadsheets?  I have a similar problem, I am writing a C# program that needs to fetch data from XL Spreadsheets with least human interactions as this also has to be something processed in batch or sort of a windows service. using various techniques like GetObject or its equivalents in C#, I was able to get first get or create excel instance and then reading data from password protected spreadsheet but that prompts with a password dialog that I don't want to appear. I want a silent way of entering a password for the excel file to read it. Any findings yet?

    Thanks,
    AQ
    Tuesday, September 22, 2009 11:11 AM