2010-07-23 6 views
6

J'ai passé beaucoup de temps à essayer de trouver un bon moyen d'intégrer n'importe quel fichier dans Microsoft Word en utilisant OpenXml 2.0; Les documents Office sont assez faciles mais qu'en est-il d'autres types de fichiers tels que PDF, TXT, GIF, JPG, HTML, etc ....Comment puis-je intégrer n'importe quel type de fichier dans Microsoft Word en utilisant OpenXml 2.0

Quelle est une bonne façon de faire fonctionner cela pour n'importe quel type de fichier, en C#?

+2

Note pour les implémenteurs du code ci-dessous - il utilise Interop, il ne s'agit donc pas d'une pure solution Open XML SDK. –

Répondre

18

incorporation d'objets étrangers (PDF, TXT, GIF, etc ...) dans Microsoft Word à l'aide OpenXml 2.0 (Eh bien, en collaboration avec COM)

Je suis beaucoup sur ce site, alors voici j'ai demandé et a répondu à ma propre question afin de redonner un peu sur un sujet dans lequel j'ai eu du mal à trouver des réponses, j'espère que cela aidera les gens. Il existe plusieurs exemples qui montrent comment intégrer un document Office dans un autre document Office à l'aide d'OpenXml 2.0, ce qui n'est pas évident et comment l'intégrer à n'importe quel fichier dans Office Document est facile à comprendre.

J'ai beaucoup appris du code d'autres personnes, donc c'est ma tentative de contribuer. Comme j'utilise déjà OpenXml pour générer des documents et que j'ai besoin d'incorporer d'autres fichiers dans Word, j'ai décidé d'utiliser une collaboration d'OpenXml et COM (Microsoft Office 2007 dll) pour atteindre mon objectif. Si vous êtes comme moi, "invoquer l'application serveur OLE pour créer un IStorage" ne signifie pas grand chose pour vous.

Dans cet exemple, j'aimerais montrer comment j'utilise COM pour obtenir PROGRÉTIQUEMENT les informations de données OLE-binaires du fichier joint, puis comment j'ai utilisé cette information dans mon document OpenXml. Fondamentalement, je regarde par programme le réflecteur de document d'OpenXml 2.0 pour obtenir l'information dont j'ai besoin.

Mon code ci-dessous est décomposé en plusieurs classes, mais voici un aperçu de ce que je fais:

  1. Créer un OpenXml WordprocessingDocument, obtenir le System.IO.FileInfo le fichier que vous voulez Intégrer
  2. Créer un objet OpenXmlEmbeddedObject personnalisé (ce que contient toutes les données binaires)
  3. Utilisez les données binaires de l'étape ci-dessus pour créer des données et l'image Streams
  4. Utilisez les cours d'eau comme l'objet de fichier et l'image du fichier pour votre OpenXml document

Je sais qu'il ya beaucoup de code, et pas beaucoup d'explication ... Espérons qu'il est facile à suivre et je aider les gens 

Exigences: • dll DocumentFormat.OpenXml (OpenXML 2.0) • WindowsBase dll • Microsoft.Office.Interop.dll Word (Office 2007 - Version 12)

• Cette classe principale qui commence tout, ouvre une WordprocessingDocument et la classe d'avoir le fichier joint

using DocumentFormat.OpenXml.Packaging; 
using System.IO; 
using DocumentFormat.OpenXml; 
using DocumentFormat.OpenXml.Wordprocessing; 

public class MyReport 
{ 
    private MainDocumentPart _mainDocumentPart; 

    public void CreateReport() 
    { 
     using (WordprocessingDocument wpDocument = WordprocessingDocument.Create(@"TempPath\MyReport.docx", WordprocessingDocumentType.Document)) 
     { 
      _mainDocumentPart = wpDocument.AddMainDocumentPart(); 
      _mainDocumentPart.Document = new Document(new Body()); 

      AttachFile(@"MyFilePath\MyFile.pdf", true); 
     } 
    } 

    private void AttachFile(string filePathAndName, bool displayAsIcon) 
    { 
     FileInfo fileInfo = new FileInfo(filePathAndName); 

     OpenXmlHelper.AppendEmbeddedObject(_mainDocumentPart, fileInfo, displayAsIcon); 
    } 
} 

• Cette classe dans une classe d'aide OpenXml , détient toute la logique d'intégrer un objet dans votre fichier OpenXml

using DocumentFormat.OpenXml; 
using DocumentFormat.OpenXml.Packaging; 
using DocumentFormat.OpenXml.Validation; 
using DocumentFormat.OpenXml.Wordprocessing; 
using OVML = DocumentFormat.OpenXml.Vml.Office; 
using V = DocumentFormat.OpenXml.Vml; 

public class OpenXmlHelper 
{ 
    /// <summary> 
    /// Appends an Embedded Object into the specified Main Document 
    /// </summary> 
    /// <param name="mainDocumentPart">The MainDocument Part of your OpenXml Word Doc</param> 
    /// <param name="fileInfo">The FileInfo object associated with the file being embedded</param> 
    /// <param name="displayAsIcon">Whether or not to display the embedded file as an Icon (Otherwise it will display a snapshot of the file)</param> 
    public static void AppendEmbeddedObject(MainDocumentPart mainDocumentPart, FileInfo fileInfo, bool displayAsIcon) 
    { 
     OpenXmlEmbeddedObject openXmlEmbeddedObject = new OpenXmlEmbeddedObject(fileInfo, displayAsIcon); 

     if (!String.IsNullOrEmpty(openXmlEmbeddedObject.OleObjectBinaryData)) 
     { 
      using (Stream dataStream = new MemoryStream(Convert.FromBase64String(openXmlEmbeddedObject.OleObjectBinaryData))) 
      { 
       if (!String.IsNullOrEmpty(openXmlEmbeddedObject.OleImageBinaryData)) 
       { 
        using (Stream emfStream = new MemoryStream(Convert.FromBase64String(openXmlEmbeddedObject.OleImageBinaryData))) 
        { 
         string imagePartId = GetUniqueXmlItemID(); 
         ImagePart imagePart = mainDocumentPart.AddImagePart(ImagePartType.Emf, imagePartId); 

         if (emfStream != null) 
         { 
          imagePart.FeedData(emfStream); 
         } 

         string embeddedPackagePartId = GetUniqueXmlItemID(); 

         if (dataStream != null) 
         { 
          if (openXmlEmbeddedObject.ObjectIsOfficeDocument) 
          { 
           EmbeddedPackagePart embeddedObjectPart = mainDocumentPart.AddNewPart<EmbeddedPackagePart>(
            openXmlEmbeddedObject.FileContentType, embeddedPackagePartId); 
           embeddedObjectPart.FeedData(dataStream); 
          } 
          else 
          { 
           EmbeddedObjectPart embeddedObjectPart = mainDocumentPart.AddNewPart<EmbeddedObjectPart>(
            openXmlEmbeddedObject.FileContentType, embeddedPackagePartId); 
           embeddedObjectPart.FeedData(dataStream); 
          } 
         } 

         if (!displayAsIcon && !openXmlEmbeddedObject.ObjectIsPicture) 
         { 
          Paragraph attachmentHeader = CreateParagraph(String.Format("Attachment: {0} (Double-Click to Open)", fileInfo.Name)); 
          mainDocumentPart.Document.Body.Append(attachmentHeader); 
         } 

         Paragraph embeddedObjectParagraph = GetEmbeededObjectParagraph(openXmlEmbeddedObject.FileType, 
          imagePartId, openXmlEmbeddedObject.OleImageStyle, embeddedPackagePartId); 

         mainDocumentPart.Document.Body.Append(embeddedObjectParagraph); 
        } 
       } 
      } 
     } 
    } 

    /// <summary> 
    /// Gets Paragraph that includes the embedded object 
    /// </summary> 
    private static Paragraph GetEmbeededObjectParagraph(string fileType, string imageID, string imageStyle, string embeddedPackageID) 
    { 
     EmbeddedObject embeddedObject = new EmbeddedObject(); 

     string shapeID = GetUniqueXmlItemID(); 
     V.Shape shape = new V.Shape() { Id = shapeID, Style = imageStyle }; 
     V.ImageData imageData = new V.ImageData() { Title = "", RelationshipId = imageID }; 

     shape.Append(imageData); 
     OVML.OleObject oleObject = new OVML.OleObject() 
     { 
      Type = OVML.OleValues.Embed, 
      ProgId = fileType, 
      ShapeId = shapeID, 
      DrawAspect = OVML.OleDrawAspectValues.Icon, 
      ObjectId = GetUniqueXmlItemID(), 
      Id = embeddedPackageID 
     }; 

     embeddedObject.Append(shape); 
     embeddedObject.Append(oleObject); 

     Paragraph paragraphImage = new Paragraph(); 

     Run runImage = new Run(embeddedObject); 
     paragraphImage.Append(runImage); 

     return paragraphImage; 
    } 

    /// <summary> 
    /// Gets a Unique ID for an XML Item, for reference purposes 
    /// </summary> 
    /// <returns>A GUID string with removed dashes</returns> 
    public static string GetUniqueXmlItemID() 
    { 
     return "r" + System.Guid.NewGuid().ToString().Replace("-", ""); 
    } 

    private static Paragraph CreateParagraph(string paragraphText) 
    { 
     Paragraph paragraph = new Paragraph(); 
     ParagraphProperties paragraphProperties = new ParagraphProperties(); 

     paragraphProperties.Append(new Justification() 
     { 
      Val = JustificationValues.Left 
     }); 

     paragraphProperties.Append(new SpacingBetweenLines() 
     { 
      After = Convert.ToString(100), 
      Line = Convert.ToString(100), 
      LineRule = LineSpacingRuleValues.AtLeast 
     }); 

     Run run = new Run(); 
     RunProperties runProperties = new RunProperties(); 

     Text text = new Text(); 

     if (!String.IsNullOrEmpty(paragraphText)) 
     { 
      text.Text = paragraphText; 
     } 

     run.Append(runProperties); 
     run.Append(text); 

     paragraph.Append(paragraphProperties); 
     paragraph.Append(run); 

     return paragraph; 
    } 

} 

• Ceci est la partie la plus importante de ce processus, il utilise le serveur OLE interne de Microsoft, crée les informations Binary DATA et binaire EMF pour un fichier. Tout ce que vous avez à faire ici est d'appeler le constructeur OpenXmlEmbeddedObject et tout est pris en charge. Il va imiter le processus qui se passe lorsque vous faites glisser manuellement un fichier dans Word; il y a une sorte de conversion qui se passe quand vous faites cela, en tournant le fichier dans un objet OLE, afin que Microsoft puisse reconnaître le fichier. o Les parties les plus importantes de cette classe sont les propriétés OleObjectBinaryData et OleImageBinaryData; ils contiennent l'information binaire de la chaîne 64Bit pour les données du fichier et l'image '.emf'. o Si vous choisissez de ne pas afficher le fichier en tant qu'icône, les données d'image '.emf' créeront un instantané du fichier, comme la première page du fichier pdf par exemple, dans lequel vous pouvez toujours cliquer deux fois sur ouvert o Si vous intégrez une image et choisissez de ne pas l'afficher comme une icône, les propriétés OleObjectBinaryData et OleImageBinaryData sera le même

using System.Runtime.InteropServices; 
using System.Xml; 
using System.Diagnostics; 
using System.IO; 
using System.Drawing; 
using Microsoft.Office.Interop.Word; 

public class OpenXmlEmbeddedObject 
{ 
    #region Constants 

    private const string _defaultOleContentType = "application/vnd.openxmlformats-officedocument.oleObject"; 
    private const string _oleObjectDataTag = "application/vnd"; 
    private const string _oleImageDataTag = "image/x-emf"; 

    #endregion Constants 

    #region Member Variables 

    private static FileInfo _fileInfo; 
    private static string _filePathAndName; 
    private static bool _displayAsIcon; 
    private static bool _objectIsPicture; 

    private object _objectMissing = System.Reflection.Missing.Value; 
    private object _objectFalse = false; 
    private object _objectTrue = true; 

    #endregion Member Variables 

    #region Properties 

    /// <summary> 
    /// The File Type, as stored in Registry (Ex: a GIF Image = 'giffile') 
    /// </summary> 
    public string FileType 
    { 
     get 
     { 
      if (String.IsNullOrEmpty(_fileType) && _fileInfo != null) 
      { 
       _fileType = GetFileType(_fileInfo, false); 
      } 

      return _fileType; 
     } 
    } 
    private string _fileType; 

    /// <summary> 
    /// The File Context Type, as storered in Registry (Ex: a GIF Image = 'image/gif') 
    /// * Is converted into the 'Default Office Context Type' for non-office files 
    /// </summary> 
    public string FileContentType 
    { 
     get 
     { 
      if (String.IsNullOrEmpty(_fileContentType) && _fileInfo != null) 
      { 
       _fileContentType = GetFileContentType(_fileInfo); 

       if (!_fileContentType.Contains("officedocument")) 
       { 
        _fileContentType = _defaultOleContentType; 
       } 
      } 

      return _fileContentType; 
     } 
    } 
    private string _fileContentType; 

    /// <summary> 
    /// Gets the ContentType Text for the file 
    /// </summary> 
    public static string GetFileContentType(FileInfo fileInfo) 
    { 
     if (fileInfo == null) 
     { 
      throw new ArgumentNullException("fileInfo"); 
     } 

     string mime = "application/octetstream"; 

     string ext = System.IO.Path.GetExtension(fileInfo.Name).ToLower(); 

     Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext); 

     if (rk != null && rk.GetValue("Content Type") != null) 
     { 
      mime = rk.GetValue("Content Type").ToString(); 
     } 

     return mime; 
    } 

    public bool ObjectIsOfficeDocument 
    { 
     get { return FileContentType != _defaultOleContentType; } 
    } 

    public bool ObjectIsPicture 
    { 
     get { return _objectIsPicture; } 
    } 

    public string OleObjectBinaryData 
    { 
     get { return _oleObjectBinaryData; } 
     set { _oleObjectBinaryData = value; } 
    } 
    private string _oleObjectBinaryData; 

    public string OleImageBinaryData 
    { 
     get { return _oleImageBinaryData; } 
     set { _oleImageBinaryData = value; } 
    } 
    private string _oleImageBinaryData; 

    /// <summary> 
    /// The OpenXml information for the Word Application that is created (Make-Shoft Code Reflector) 
    /// </summary> 
    public string WordOpenXml 
    { 
     get { return _wordOpenXml; } 
     set { _wordOpenXml = value; } 
    } 
    private String _wordOpenXml; 

    /// <summary> 
    /// The XmlDocument that is created based on the OpenXml Data from WordOpenXml 
    /// </summary> 
    public XmlDocument OpenXmlDocument 
    { 
     get 
     { 
      if (_openXmlDocument == null && !String.IsNullOrEmpty(WordOpenXml)) 
      { 
       _openXmlDocument = new XmlDocument(); 
       _openXmlDocument.LoadXml(WordOpenXml); 
      } 

      return _openXmlDocument; 
     } 
    } 
    private XmlDocument _openXmlDocument; 

    /// <summary> 
    /// The XmlNodeList, for all Nodes containing 'binaryData' 
    /// </summary> 
    public XmlNodeList BinaryDataXmlNodesList 
    { 
     get 
     { 
      if (_binaryDataXmlNodesList == null && OpenXmlDocument != null) 
      { 
       _binaryDataXmlNodesList = OpenXmlDocument.GetElementsByTagName("pkg:binaryData"); 
      } 

      return _binaryDataXmlNodesList; 
     } 
    } 
    private XmlNodeList _binaryDataXmlNodesList; 

    /// <summary> 
    /// Icon Object for the file 
    /// </summary> 
    public Icon ObjectIcon 
    { 
     get 
     { 
      if (_objectIcon == null) 
      { 
       _objectIcon = Enterprise.Windows.Win32.Win32.GetLargeIcon(_filePathAndName); 
      } 

      return _objectIcon; 
     } 
    } 
    private Icon _objectIcon; 

    /// <summary> 
    /// File Name for the Icon being created 
    /// </summary> 
    public string ObjectIconFile 
    { 
     get 
     { 
      if (String.IsNullOrEmpty(_objectIconFile)) 
      { 
       _objectIconFile = String.Format("{0}.ico", _filePathAndName.Replace(".", "")); 
      } 

      return _objectIconFile; 
     } 
    } 
    private string _objectIconFile; 

    /// <summary> 
    /// Gets the original height and width of the emf file being created 
    /// </summary> 
    public string OleImageStyle 
    { 
     get 
     { 
      if (String.IsNullOrEmpty(_oleImageStyle) && !String.IsNullOrEmpty(WordOpenXml)) 
      { 
       XmlNodeList xmlNodeList = OpenXmlDocument.GetElementsByTagName("v:shape"); 
       if (xmlNodeList != null && xmlNodeList.Count > 0) 
       { 
        foreach (XmlAttribute attribute in xmlNodeList[0].Attributes) 
        { 
         if (attribute.Name == "style") 
         { 
          _oleImageStyle = attribute.Value; 
         } 
        } 
       } 
      } 

      return _oleImageStyle; 
     } 

     set { _oleImageStyle = value; } 
    } 
    private string _oleImageStyle; 

    #endregion Properties 

    #region Constructor 

    /// <summary> 
    /// Generates binary information for the file being passed in 
    /// </summary> 
    /// <param name="fileInfo">The FileInfo object for the file to be embedded</param> 
    /// <param name="displayAsIcon">Whether or not to display the file as an Icon (Otherwise it will show a snapshot view of the file)</param> 
    public OpenXmlEmbeddedObject(FileInfo fileInfo, bool displayAsIcon) 
    { 
     _fileInfo = fileInfo; 
     _filePathAndName = fileInfo.ToString(); 
     _displayAsIcon = displayAsIcon; 

     SetupOleFileInformation(); 
    } 

    #endregion Constructor 

    #region Methods 

    /// <summary> 
    /// Creates a temporary Word App in order to add an OLE Object, get's the OpenXML data from the file (similar to the Code Reflector info) 
    /// </summary> 
    private void SetupOleFileInformation() 
    { 
     Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application(); 

     Microsoft.Office.Interop.Word.Document wordDocument = wordApplication.Documents.Add(ref _objectMissing, ref _objectMissing, 
      ref _objectMissing, ref _objectMissing); 

     object iconObjectFileName = _objectMissing; 
     object objectClassType = FileType; 
     object objectFilename = _fileInfo.ToString(); 

     Microsoft.Office.Interop.Word.InlineShape inlineShape = null; 

     if (_displayAsIcon) 
     { 
      if (ObjectIcon != null) 
      { 
       using (FileStream iconStream = new FileStream(ObjectIconFile, FileMode.Create)) 
       { 
        ObjectIcon.Save(iconStream); 
        iconObjectFileName = ObjectIconFile; 
       } 
      } 

      object objectIconLabel = _fileInfo.Name; 

      inlineShape = wordDocument.InlineShapes.AddOLEObject(ref objectClassType, 
       ref objectFilename, ref _objectFalse, ref _objectTrue, ref iconObjectFileName, 
       ref _objectMissing, ref objectIconLabel, ref _objectMissing); 
     } 
     else 
     { 
      try 
      { 
       Image image = Image.FromFile(_fileInfo.ToString()); 
       _objectIsPicture = true; 
       OleImageStyle = String.Format("height:{0}pt;width:{1}pt", image.Height, image.Width); 

       wordDocument.InlineShapes.AddPicture(_fileInfo.ToString(), ref _objectMissing, ref _objectTrue, ref _objectMissing); 
      } 
      catch 
      { 
       inlineShape = wordDocument.InlineShapes.AddOLEObject(ref objectClassType, 
        ref objectFilename, ref _objectFalse, ref _objectFalse, ref _objectMissing, ref _objectMissing, 
        ref _objectMissing, ref _objectMissing); 
      } 
     } 

     WordOpenXml = wordDocument.Range(ref _objectMissing, ref _objectMissing).WordOpenXML; 

     if (_objectIsPicture) 
     { 
      OleObjectBinaryData = GetPictureBinaryData(); 
      OleImageBinaryData = GetPictureBinaryData(); 
     } 
     else 
     { 
      OleObjectBinaryData = GetOleBinaryData(_oleObjectDataTag); 
      OleImageBinaryData = GetOleBinaryData(_oleImageDataTag); 
     } 

     // Not sure why, but Excel seems to hang in the processes if you attach an Excel file… 
     // This kills the excel process that has been started < 15 seconds ago (so not to kill the user's other Excel processes that may be open) 
     if (FileType.StartsWith("Excel")) 
     { 
      Process[] processes = Process.GetProcessesByName("EXCEL"); 
      foreach (Process process in processes) 
      { 
       if (DateTime.Now.Subtract(process.StartTime).Seconds <= 15) 
       { 
        process.Kill(); 
        break; 
       } 
      } 
     } 

     wordDocument.Close(ref _objectFalse, ref _objectMissing, ref _objectMissing); 
     wordApplication.Quit(ref _objectMissing, ref _objectMissing, ref _objectMissing); 
    } 

    /// <summary> 
    /// Gets the binary data from the Xml File that is associated with the Tag passed in 
    /// </summary> 
    /// <param name="binaryDataXmlTag">the Tag to look for in the OpenXml</param> 
    /// <returns></returns> 
    private string GetOleBinaryData(string binaryDataXmlTag) 
    { 
     string binaryData = null; 
     if (BinaryDataXmlNodesList != null) 
     { 
      foreach (XmlNode xmlNode in BinaryDataXmlNodesList) 
      { 
       if (xmlNode.ParentNode != null) 
       { 
        foreach (XmlAttribute attr in xmlNode.ParentNode.Attributes) 
        { 
         if (String.IsNullOrEmpty(binaryData) && attr.Value.Contains(binaryDataXmlTag)) 
         { 
          binaryData = xmlNode.InnerText; 
          break; 
         } 
        } 
       } 
      } 
     } 

     return binaryData; 
    } 

    /// <summary> 
    /// Gets the image Binary data, if the file is an image 
    /// </summary> 
    /// <returns></returns> 
    private string GetPictureBinaryData() 
    { 
     string binaryData = null; 
     if (BinaryDataXmlNodesList != null) 
     { 
      foreach (XmlNode xmlNode in BinaryDataXmlNodesList) 
      { 
       binaryData = xmlNode.InnerText; 
       break; 
      } 
     } 

     return binaryData; 
    } 

    /// <summary> 
    /// Gets the file type description ("Application", "Text Document", etc.) for the file. 
    /// </summary> 
    /// <param name="fileInfo">FileInfo containing extention</param> 
    /// <returns>Type Description</returns> 
    public static string GetFileType(FileInfo fileInfo, bool returnDescription) 
    { 
     if (fileInfo == null) 
     { 
      throw new ArgumentNullException("fileInfo"); 
     } 

     string description = "File"; 
     if (string.IsNullOrEmpty(fileInfo.Extension)) 
     { 
      return description; 
     } 
     description = string.Format("{0} File", fileInfo.Extension.Substring(1).ToUpper()); 
     RegistryKey typeKey = Registry.ClassesRoot.OpenSubKey(fileInfo.Extension); 
     if (typeKey == null) 
     { 
      return description; 
     } 
     string type = Convert.ToString(typeKey.GetValue(string.Empty)); 
     RegistryKey key = Registry.ClassesRoot.OpenSubKey(type); 
     if (key == null) 
     { 
      return description; 
     } 

     if (returnDescription) 
     { 
      description = Convert.ToString(key.GetValue(string.Empty)); 
      return description; 
     } 
     else 
     { 
      return type; 
     } 
    } 

    #endregion Methods 
} 
+0

Il existe un bug @ line 263. Les chemins de fichiers relationnels provoquent une erreur et une fenêtre contextuelle à partir de Word. "object objectFilename = _fileInfo.ToString();" devrait lire "object objectFilename = _fileInfo.FullName;" au lieu. – bic

+0

Avez-vous une idée de comment modifier l'objet Excel incorporé? Lorsque je double-clique dessus, il ouvre un nouveau programme Excel dans lequel je peux le modifier, mais il ne met jamais à jour le document Word original. Merci. – jn1kk

+0

Ceci est un bon exemple, mais que se passe-t-il si je dois inverser obtenir le fichier (de préférence l'image) de tels objets incorporés ole. – serene

0

Ma réponse here va dire vous comment faire cela, mais pas afficher vous avec le SDK ou une langue spécifique.

0
_objectIcon = Enterprise.Windows.Win32.Win32.GetLargeIcon(_filePathAndName); 

semble être rompu, mais

_objectIcon = System.Drawing.Icon.ExtractAssociatedIcon(_filePathAndName); 

devrait également fonctionner.

0

Ceci est une excellente réponse et il m'a beaucoup aidé, mais le bug potentiel bic utilisateur mentionné existe également

dans

OpenXmlEmbeddedObject(FileInfo fileInfo, bool displayAsIcon) 

à la ligne 242,

_filePathAndName = fileInfo.ToString(); 

dans

SetupOleFileInformation() 

à la ligne 264,

object objectFilename = _fileInfo.ToString(); 

ligne 289, et

Image image = Image.FromFile(_fileInfo.ToString()); 

ligne 293

wordDocument.InlineShapes.AddPicture(_fileInfo.toString(), ref _objectMissing, ref _objectTrue, ref _objectMissing); 

Tous ces éléments doivent être "FullName" au lieu de "ToString()" si le le code devrait aussi fonctionner avec des chemins relatifs. J'espère que cela aidera tous ceux qui veulent utiliser le code de D Lyonnais!

Questions connexes