本文整理汇总了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);
}
}
示例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?
}
}
}
示例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);
}
}