本文整理汇总了C#中OpenXmlPowerTools.WmlDocument类的典型用法代码示例。如果您正苦于以下问题:C# WmlDocument类的具体用法?C# WmlDocument怎么用?C# WmlDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WmlDocument类属于OpenXmlPowerTools命名空间,在下文中一共展示了WmlDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToc
public static WmlDocument AddToc(WmlDocument document, string xPath, string switches, string title, int? rightTabPos)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
{
using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
{
AddToc(doc, xPath, switches, title, rightTabPos);
}
return streamDoc.GetModifiedWmlDocument();
}
}
示例2: GetAllComments
public static object GetAllComments(WmlDocument doc, CommentFormat format)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
{
IEnumerable<XElement> comments = null;
WordprocessingCommentsPart commentsPart = document.MainDocumentPart.WordprocessingCommentsPart;
if (commentsPart != null)
{
XDocument commentsPartDocument = commentsPart.GetXDocument();
comments = commentsPartDocument.Element(W.comments).Elements(W.comment);
}
if (comments != null)
{
XDocument commentsDocument =
new XDocument(
new XElement(W.comments,
new XAttribute(XNamespace.Xmlns + "w", W.w),
comments
)
);
switch (format)
{
case CommentFormat.PlainText:
return commentsDocument.ToString();
case CommentFormat.Xml:
return commentsDocument;
case CommentFormat.Docx:
return CreateCommentsDocument(comments);
}
}
return null;
}
}
示例3: mergeDocx
static void mergeDocx(string paramOutputFile, List<FileStream> paramDocumentstreams)
{
var sources = new List<Source>();
try
{
foreach (var stream in paramDocumentstreams)
{
var tempms = new MemoryStream();
if (0 != stream.Length)
{
stream.CopyTo(tempms);
WmlDocument doc = new WmlDocument(stream.Length.ToString(), tempms);
sources.Add(new Source(doc, true));
}
tempms.Close();
}
Console.WriteLine("Merging documents...");
var mergedDoc = DocumentBuilder.BuildDocument(sources);
mergedDoc.SaveAs(paramOutputFile);
}
catch (Exception e)
{
Console.WriteLine("An Error ocurred while merging, please check the log: ");
Console.WriteLine(e.ToString());
}
}
示例4: Source
public Source(WmlDocument source, int start, int count, bool keepSections)
{
WmlDocument = source;
Start = start;
Count = count;
KeepSections = keepSections;
}
示例5: Source
public Source(WmlDocument source, int start, int count, string insertId)
{
WmlDocument = source;
Start = start;
Count = count;
KeepSections = false;
InsertId = insertId;
}
示例6: Source
public Source(string fileName, bool keepSections)
{
WmlDocument = new WmlDocument(fileName);
Start = 0;
Count = Int32.MaxValue;
KeepSections = keepSections;
InsertId = null;
}
示例7: Source
public Source(string fileName, string insertId)
{
WmlDocument = new WmlDocument(fileName);
Start = 0;
Count = Int32.MaxValue;
KeepSections = false;
InsertId = insertId;
}
示例8: Insert
/// <summary>
/// Inserts Xml markup representing format attributes inside a specific paragraph or paragraph run
/// </summary>
/// <param name="document">Document to insert formatting Xml tags</param>
/// <param name="xpathInsertionPoint">Paragraph or paragraph run to set format</param>
/// <param name="content">Formatting tags</param>
public static OpenXmlPowerToolsDocument Insert(WmlDocument doc, string xpathInsertionPoint, string content)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
{
using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
{
XDocument xDocument = document.MainDocumentPart.GetXDocument();
XmlDocument xmlMainDocument = new XmlDocument();
xmlMainDocument.Load(xDocument.CreateReader());
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
namespaceManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
XmlNodeList insertionPoints = xmlMainDocument.SelectNodes(xpathInsertionPoint, namespaceManager);
if (insertionPoints.Count == 0)
throw new ArgumentException("The xpath query did not return a valid location.");
foreach (XmlNode insertionPoint in insertionPoints)
{
XmlNode propertiesElement = insertionPoint.SelectSingleNode(@"w:pPr|w:rPr", namespaceManager);
if (insertionPoint.Name == "w:p")
{
// Checks if the rPr or pPr element exists
if (propertiesElement == null)
{
propertiesElement = xmlMainDocument.CreateElement("w", "pPr", namespaceManager.LookupNamespace("w"));
insertionPoint.PrependChild(propertiesElement);
}
}
else if (insertionPoint.Name == "w:r")
{
// Checks if the rPr or pPr element exists
if (propertiesElement == null)
{
propertiesElement = xmlMainDocument.CreateElement("w", "rPr", namespaceManager.LookupNamespace("w"));
insertionPoint.PrependChild(propertiesElement);
}
}
if (propertiesElement != null)
{
propertiesElement.InnerXml += content;
}
else
{
throw new ArgumentException("Specified xpath query result is not a valid location to place a formatting markup");
}
}
XDocument xNewDocument = new XDocument();
using (XmlWriter xWriter = xNewDocument.CreateWriter())
xmlMainDocument.WriteTo(xWriter);
document.MainDocumentPart.PutXDocument(xNewDocument);
}
return streamDoc.GetModifiedDocument();
}
}
示例9: PtWordprocessingCommentsPart
public PtWordprocessingCommentsPart(WmlDocument wmlDocument, Uri uri, XName name, params object[] values)
: base(name, values)
{
ParentWmlDocument = wmlDocument;
this.Add(
new XAttribute(PtOpenXml.Uri, uri),
new XAttribute(XNamespace.Xmlns + "pt", PtOpenXml.pt)
);
}
示例10: RA001_RevisionAccepter
public void RA001_RevisionAccepter(string name)
{
FileInfo sourceDocx = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, name));
WmlDocument notAccepted = new WmlDocument(sourceDocx.FullName);
WmlDocument afterAccepting = RevisionAccepter.AcceptRevisions(notAccepted);
var processedDestDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", "-processed-by-RevisionAccepter.docx")));
afterAccepting.SaveAs(processedDestDocx.FullName);
}
示例11: GetBackgroundColor
public static string GetBackgroundColor(WmlDocument doc)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
{
XDocument mainDocument = document.MainDocumentPart.GetXDocument();
XElement backgroundElement = mainDocument.Descendants(W.background).FirstOrDefault();
return (backgroundElement == null) ? string.Empty : backgroundElement.Attribute(W.color).Value;
}
}
示例12: ConvertToHtml
public static XElement ConvertToHtml(WmlDocument doc, HtmlConverterSettings htmlConverterSettings, Func<ImageInfo, XElement> imageHandler)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
{
using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
{
return ConvertToHtml(document, htmlConverterSettings, imageHandler);
}
}
}
示例13: RetrieveListItem
public static string RetrieveListItem(WmlDocument document,
XElement paragraph, string bulletReplacementString)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
{
using (WordprocessingDocument wdoc = streamDoc.GetWordprocessingDocument())
{
return RetrieveListItem(wdoc, paragraph, bulletReplacementString);
}
}
}
示例14: GetFooter
/// <summary>
/// Get the specified footer from the document
/// </summary>
/// <param name="type">The footer part type</param>
/// <returns>the XDocument containing the footer</returns>
public static XDocument GetFooter(WmlDocument doc, FooterType type, int sectionIndex)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
{
OpenXmlPart footer = GetFooterPart(document, type, sectionIndex);
if (footer != null)
return footer.GetXDocument();
return null;
}
}
示例15: AssembleFormatting
public static WmlDocument AssembleFormatting(WmlDocument document, FormattingAssemblerSettings settings)
{
using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
{
using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
{
AssembleFormatting(doc, settings);
}
return streamDoc.GetModifiedWmlDocument();
}
}