当前位置: 首页>>代码示例>>C#>>正文


C# Paragraph.AppendChild方法代码示例

本文整理汇总了C#中DocumentFormat.OpenXml.Drawing.Paragraph.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# Paragraph.AppendChild方法的具体用法?C# Paragraph.AppendChild怎么用?C# Paragraph.AppendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentFormat.OpenXml.Drawing.Paragraph的用法示例。


在下文中一共展示了Paragraph.AppendChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddObject

        /// <summary>
        /// Embeds an object with an extension included in the validImageExtensions, officeXmlExtensions, officeBasicExtensions, or validObjectExtensions Lists.
        /// </summary>
        /// <param name="realFileName">Full path to the file.</param>
        /// <param name="displayFileName">Name displayed under the file icon in the document.</param>
        public void AddObject(String realFileName, String displayFileName)
        {
            String filePath = realFileName;
            Paragraph para = new Paragraph();
            Run run = null;
            if (File.Exists(filePath))
            {
                MainDocumentPart mainPart = _package.MainDocumentPart;

                ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png);
                GenerateImage(imagePart, displayFileName);

                String extension = Path.GetExtension(filePath);
                String contentType = GetContentType(extension);
                if (officeXmlExtensions.Contains(extension))
                {
                    EmbeddedPackagePart embeddedPackagePart = _package.MainDocumentPart.AddEmbeddedPackagePart(contentType);
                    using (FileStream stream = new FileStream(filePath, FileMode.Open))
                    {
                        embeddedPackagePart.FeedData(stream);
                    }
                    run = GetObjectRun(mainPart.GetIdOfPart(imagePart), mainPart.GetIdOfPart(embeddedPackagePart), extension);
                }
                else if (officeBasicExtensions.Contains(extension))
                {
                    EmbeddedObjectPart embeddedObjectPart = _package.MainDocumentPart.AddEmbeddedObjectPart(contentType);
                    using (FileStream stream = new FileStream(filePath, FileMode.Open))
                    {
                        embeddedObjectPart.FeedData(stream);
                    }
                    run = GetObjectRun(mainPart.GetIdOfPart(imagePart), mainPart.GetIdOfPart(embeddedObjectPart), extension);
                }
                else if (validObjectExtensions.Contains(extension))
                {
                    StringBuilder errorMessages;
                    EmbeddedObjectPart embeddedObjectPart = _package.MainDocumentPart.AddEmbeddedObjectPart(contentType);
                    String outputBinaryName = GetBinaryName(filePath);
                    bool success = GenerateOleObject(filePath, outputBinaryName, out errorMessages);
                    if (success)
                    {
                        using (FileStream stream = new FileStream(outputBinaryName, FileMode.Open))
                        {
                            embeddedObjectPart.FeedData(stream);
                        }
                        try
                        {
                            File.Delete(outputBinaryName);
                            run = GetObjectRun(mainPart.GetIdOfPart(imagePart), mainPart.GetIdOfPart(embeddedObjectPart), extension);

                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Failed to remove file: {0}", outputBinaryName);
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Failed to generate OLE Object: {0}", filePath);
                    }
                }
                else
                {
                    Debug.WriteLine("Invalid file format: {0}", filePath);
                }
                para.AppendChild(run);
                _document.Append(para);
            }
            else
            {
                Debug.WriteLine("File not found: {0}", filePath);
            }
        }
开发者ID:vandersmissenc,项目名称:OpenXmlDocumentGenerator,代码行数:77,代码来源:OpenXmlHelper.cs

示例2: Process

        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (IsHidden(node))
            {
                return;
            }

            string src = node.ExtractAttributeValue("src");

            if (!string.IsNullOrEmpty(src))
            {
                try
                {
                    Drawing drawing = PrepareImage(src);

                    if (drawing != null)
                    {
                        if (paragraph == null)
                        {
                            paragraph = node.Parent.AppendChild(new Paragraph());
                            OnParagraphCreated(node, paragraph);
                        }

                        Run run = paragraph.AppendChild(new Run(drawing));
                        RunCreated(node, run);
                    }
                }
                catch
                {
                    return;//fails silently?
                }
            }
        }
开发者ID:kannan-ar,项目名称:MariGold.OpenXHTML,代码行数:33,代码来源:DocxImage.cs

示例3: AddImage

 /// <summary>
 /// Embeds an image within the document.
 /// </summary>
 /// <param name="filePath">File path to the image to embed.</param>
 public void AddImage(String filePath)
 {
     Paragraph para = new Paragraph();
     Run run = null;
     if (File.Exists(filePath))
     {
         String extension = Path.GetExtension(filePath);
         if (validImageExtensions.Contains(extension))
         {
             ImagePartType imagePartType = GetImagePartType(extension);
             ImagePart imagePart = _package.MainDocumentPart.AddImagePart(imagePartType);
             using (FileStream stream = new FileStream(filePath, FileMode.Open))
             {
                 imagePart.FeedData(stream);
             }
             using (FileStream stream = new FileStream(filePath, FileMode.Open))
             {
                 Bitmap image = new Bitmap(stream);
                 run = GetImageRun(_package.MainDocumentPart.GetIdOfPart(imagePart), image);
                 para.AppendChild(run);
                 _document.Append(para);
             }
         }
         else
         {
             Debug.WriteLine("Invalid file format: {0}", filePath);
         }
     }
     else
     {
         Debug.WriteLine("File not found: {0}", filePath);
     }
 }
开发者ID:vandersmissenc,项目名称:OpenXmlDocumentGenerator,代码行数:37,代码来源:OpenXmlHelper.cs


注:本文中的DocumentFormat.OpenXml.Drawing.Paragraph.AppendChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。