none
"The Image part with relationship ID rId1 was not found in the file" instead of my actual image in Excel

    Question

  • Hi Friends,

    I'm displayed "The Image part with relationship ID rId1 was not found in the file" instead of my actual image in Excel.


    My logic is here ,
    -------------------

      I'm using VB.NET 2008,Excel 2010


      I'm maintaining Template Folder in Application path  which is placed on Server System .Inside Template folder i'm maintaining some excel sheets with some format with company logo,company heading & cell formats.

    now when i click Export to Excel button from VB.NET Windows application, At run time i'm doing following operation,

    step 1. i'm creating new excel sheet & Adding template sheet into this new excel sheet (from template folder which is in Server System) 

      VB.NET Code :  xlw.Sheets.Add(, , , My.Application.Info.DirectoryPath & "\Templates\DeliveryOrder.xlsx")

    step 2. Loading only data into this sheet ( since company logo,header & other cell formats already set in template sheet itself,no need to set every time )

    step 3. Saving this in Local Drive at runtime itself ( In Client System ).


    But when i open Saved excel sheet in local drive, my company logo is displaying with error image as "The Image part with relationship ID rId1 was not found in the file".


    Note :  My template folder is in Server & saved sheet in local( Client ). 


    My Questions :
    ---------------

    So i wanna know 1.why I'm getting "The Image part with relationship ID rId1 was not found in the file" error instead of my image ?
    2. Is this Excel Issue or My Vb.Net Application Issue


    friends,Can you help me to fix this issue ?


    Thanks - Ravi

    Monday, April 16, 2012 5:40 AM

Answers

  • Hi,

        Thanks for reply..

        I just found alternative solution for this problem myself.

    Previously i used Insert menu -> Picture then i chose image , i don't know why this is not working. if anyone find a solution you can share it. 

    But I used Image Control in Developer Menu. ( Developer Menu - > Insert - > Image Control ). Here i added picture through Picture Property. 

    Now Image is displaying & working perfectly.



    Thanks - Ravi


    • Marked as answer by Ravi exact Monday, April 30, 2012 11:28 AM
    • Edited by Ravi exact Monday, April 30, 2012 11:29 AM
    Monday, April 30, 2012 11:28 AM

All replies

  • Hi Ravi,

    Thank you for posting.

    Did you use Open XML SDK to manipulate the Excel sheet? I think there should be something wrong with your code when adding the images to the Excel sheet.

    Please take a look at this article about inserting images into Excel spreadsheet:

    http://polymathprogrammer.com/2009/11/30/how-to-insert-an-image-in-excel-open-xml/

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, April 17, 2012 5:57 AM
  • Hi Ravi,

    Welcome to the MSDN forum!

    As far as I know, when we insert an image into a excel sheet with "xlsx" format, the image's info is stored with the xlsx file itself. Please try the following steps:

    1.Insert a image into a new workbook's Sheet1. Save the workbook as "TestImage.xlsx", for instance.

    2. Rename the workbook from "TestImage.xlsx" to "TestImage.xlsx.zip", and unzip the file.

    The parts of a workbook with an inserted drawing(jpeg) include these root parts: _rels, docProps, xl,[Content_Types].xml  

    We can find the image we inserted at the folder xl-media.

    This is specified from the "xl/drawings/drawing1.xml": 

    <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/image1.jpg"/>

    Which configures the store location of the image, and from this following statement in "xl/worksheets/sheet1.xml":

    <drawing r:id="rId1"/></worksheet>

    You may check the target for the image in your client side. 

    Also, you may check this link to see if it work:

    http://stackoverflow.com/questions/8852411/why-would-the-excel-interop-remove-an-image-after-processing-a-file/8885187#8885187

    As explained in comments (and eventually in an edit to the question), the code was running in production as a service, with the Local Service account.

    I am now unsure why I picked this account -- something I found in passing during my research on getting the Interop to run correctly as a service?

    However, once I switched from the Local Service account to the Local System account (and checked "Allow service to interact with desktop") it worked. Automagically.

    1. services.msc
    2. select the service
    3. right-click, select "Properties"
    4. select the "Log On" tab
    5. select "Local System account" and check "Allow service to interact with desktop"

    "Allow service to interact with desktop" might not be required; Other notes on automating the Interop suggest that other desktop settings are required, however I did an install where those pre-requisites were set but THIS value unchecked; app still worked...

    http://i.imgur.com/k6Qwy.png

    Finally, according to this KB, I am afraid that server side automation of office is not recommended: http://support.microsoft.com/kb/257757 

    "Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    Hope it helps.

    Thanks.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 18, 2012 6:06 AM
  • Hi Yoyo

      Thanks for reply..

    1. 

    i do have the following in  "xl/drawings/drawing1.xml"

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><xdr:oneCellAnchor><xdr:from><xdr:col>0</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>0</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from><xdr:ext cx="1279525" cy="647700"/><xdr:pic><xdr:nvPicPr><xdr:cNvPr id="2" name="Picture 1"/><xdr:cNvPicPr><a:picLocks noChangeAspect="1" noChangeArrowheads="1"/></xdr:cNvPicPr></xdr:nvPicPr><xdr:blipFill><a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId1" cstate="print"/><a:srcRect/><a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr bwMode="auto"><a:xfrm><a:off x="0" y="0"/><a:ext cx="1279525" cy="647700"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln w="9525"><a:noFill/><a:miter lim="800000"/><a:headEnd/><a:tailEnd/></a:ln></xdr:spPr></xdr:pic><xdr:clientData/></xdr:oneCellAnchor></xdr:wsDr>

    i do not have the line anywhere what u have given  that is

    <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/image1.jpg"/>

    and 

    i do have the following code in 

    <drawing r:id="rId2"/>

    So both line is different in my output.. can you help with my output, how i can solve this.

    2.   My application is not running as Service..


    Thanks - Ravi

    Thursday, April 26, 2012 5:12 AM
  • Hi,

        Thanks for reply..

        I just found alternative solution for this problem myself.

    Previously i used Insert menu -> Picture then i chose image , i don't know why this is not working. if anyone find a solution you can share it. 

    But I used Image Control in Developer Menu. ( Developer Menu - > Insert - > Image Control ). Here i added picture through Picture Property. 

    Now Image is displaying & working perfectly.



    Thanks - Ravi


    • Marked as answer by Ravi exact Monday, April 30, 2012 11:28 AM
    • Edited by Ravi exact Monday, April 30, 2012 11:29 AM
    Monday, April 30, 2012 11:28 AM