none
Can OpenXML operate on Sharepoint Excel files?

    Question

  • When I try to open a SharePoint file, I get 'System.IO.FileNotFoundException'.

    This is the code that throws the exception.  I have of course obfuscated the actual file name.

            Using spreadsheetDocument As SpreadsheetDocument = SpreadsheetDocument.Open("https://mysite.sharepoint.com/siteName/filename.xlsx", False)
    

    mercredi 4 avril 2018 19:47

Toutes les réponses

  • Hi Dan Markoff,

    You can try to open Excel file from stream.

    If you have an application, such as Microsoft SharePoint Foundation 2010, that works with documents by using stream input/output, and you want to use the Open XML SDK 2.5 to work with one of the documents, this is designed to be easy to do. This is especially true if the document exists and you can open it using the Open XML SDK 2.5. However, suppose that the document is an open stream at the point in your code where you must use the SDK to work with it? That is the scenario for this topic. The sample method in the sample code accepts an open stream as a parameter and then adds text to the document behind the stream using the Open XML SDK 2.5.

    string strDoc = @"C:\Users\Public\Documents\Sheet11.xlsx";
    ;
    Stream stream = File.Open(strDoc, FileMode.Open);
    OpenAndAddToSpreadsheetStream(stream);
    stream.Close();

    Reference:

    How to: Open a spreadsheet document from a stream (Open XML SDK)

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    vendredi 6 avril 2018 03:18
    Modérateur
  • Does the stream work with a SharePoint file?  I can get it to work fine with local files, but it always fails on SP files, saying the file isn't found, as the OP explains.
    lundi 16 avril 2018 20:13
  • Hi Dan Markoff,

    As mentioned in the documentation, It should work.

    In some other documentation, It is mentioned that,"Opening the document using the Open XML SDK.  Trap the System.IO.FileFormatException when opening.  The Open XML SDK will throw this exception if the document isn’t valid."

    So It is possible that your document is not valid.

    I got this information from link below.

    Modifying Open XML Documents using the SharePoint Object Model

    If you are available to use SharePoint Object Model then you can also try to refer code in above link.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    mardi 17 avril 2018 05:58
    Modérateur
  • I read through your linked page, and noticed this:

    Because this is a console application that is using the SharePoint object model, you must run this code as an administrator on the box that hosts the SharePoint site.  In my case, I wrote this code inside of the virtual machine that you can find here.

    Because I am creating a clickonce application that will deploy to many users, it doesn't seem like this will work, right?

    mardi 17 avril 2018 12:42
  • Hi Dan Markoff,

    I will try to find work around for this issue and let you know about that once I get anything useful that can solve your issue.

    Thanks for your understanding.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    mercredi 18 avril 2018 08:13
    Modérateur