本文整理汇总了C#中DocumentFormat.OpenXml.Packaging.MainDocumentPart类的典型用法代码示例。如果您正苦于以下问题:C# MainDocumentPart类的具体用法?C# MainDocumentPart怎么用?C# MainDocumentPart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MainDocumentPart类属于DocumentFormat.OpenXml.Packaging命名空间,在下文中一共展示了MainDocumentPart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertContentToParagraphs
private IList<OpenXmlCompositeElement> ConvertContentToParagraphs(MainDocumentPart mainDocumentPart)
{
var converter = new HtmlConverter(mainDocumentPart) { RenderPreAsTable = false };
return converter.Parse(_content
.Replace("<img", "<img style=\"max-width:550;\"")
.Replace("<pre><code>", "<p class=\"codesnippet\"><pre>")
.Replace("</code></pre>", "</pre></p>")
.Replace("<code>", "<span class=\"inlinecodesnippet\">")
.Replace("</code>", "</span>"));
}
示例2: AppendTo
public override void AppendTo(OpenXmlElement openXmlNode, MainDocumentPart mainDocumentPart)
{
_mainDocumentPart = mainDocumentPart;
var imagePart = CreateImagePart();
openXmlNode.Append(CreateImageElement(mainDocumentPart.GetIdOfPart(imagePart), Path.GetFileName(_content)));
}
示例3: GetContentControl
/// <summary>
/// Get ContentControl from word document
/// </summary>
/// <param name="pDoc">Document mainpart</param>
/// <param name="pTag">ContentControl tag to find</param>
/// <returns>The ContentControl</returns>
public static SdtBlock GetContentControl(MainDocumentPart pDoc, string pTag)
{
SdtBlock cc = pDoc.Document.Body.Descendants<SdtBlock>().Where
(r => r.SdtProperties.GetFirstChild<Tag>().Val == pTag).Single();
return cc;
}
示例4: GetCustomXmlPart
/// <summary>
/// Gets the custom XML part.
/// </summary>
/// <param name="mainDocumentPart">The main document part.</param>
/// <returns></returns>
public CustomXmlPart GetCustomXmlPart(MainDocumentPart mainDocumentPart)
{
if (mainDocumentPart == null)
{
throw new ArgumentNullException("mainDocumentPart");
}
CustomXmlPart result = null;
foreach (CustomXmlPart part in mainDocumentPart.CustomXmlParts)
{
using (XmlTextReader reader = new XmlTextReader(part.GetStream(FileMode.Open, FileAccess.Read)))
{
reader.MoveToContent();
bool exists = reader.NamespaceURI.Equals(this.namespaceUri);
if (exists)
{
result = part;
break;
}
}
}
return result;
}
示例5: NumberingListStyleCollection
public NumberingListStyleCollection(MainDocumentPart mainPart)
{
this.mainPart = mainPart;
this.absNumId = -1;
this.numInstances = new Stack<Int32>();
InitNumberingIds();
}
示例6: GetNameToValueCollectionFromElementForType
/// <summary>
/// Gets the type of the name to value collection from element for.
/// </summary>
/// <param name="mainDocumentPart">The main document part.</param>
/// <param name="elementName">Name of the element.</param>
/// <param name="forNodeType">Type of for node.</param>
/// <returns></returns>
public Dictionary<string, string> GetNameToValueCollectionFromElementForType(MainDocumentPart mainDocumentPart, string elementName, NodeType forNodeType)
{
Dictionary<string, string> nameToValueCollection = new Dictionary<string, string>();
CustomXmlPart customXmlPart = this.customXmlPartCore.GetCustomXmlPart(mainDocumentPart);
if (customXmlPart != null)
{
XElement element = this.customXmlPartCore.GetFirstElementFromCustomXmlPart(customXmlPart, elementName);
if (element != null)
{
if (forNodeType == NodeType.Element)
{
foreach (XElement elem in element.Elements())
{
nameToValueCollection.Add(elem.Name.LocalName, elem.Nodes().Where(node => node.NodeType == XmlNodeType.Element).FirstOrDefault().ToString());
}
}
else if (forNodeType == NodeType.Attribute)
{
foreach (XAttribute attr in element.Attributes())
{
nameToValueCollection.Add(attr.Name.LocalName, attr.Value);
}
}
}
}
return nameToValueCollection;
}
示例7: GenerateParagraphWithHyperLink
/// <summary>
/// Generates a hyperlink and embed it
/// in a paragraph tag
/// </summary>
/// <param name="mainDocPart">The main doc part.</param>
/// <param name="hyperLink">The hyper link.</param>
/// <returns></returns>
public static Paragraph GenerateParagraphWithHyperLink(MainDocumentPart mainDocPart, String hyperLink)
{
//this will be display as
//the text
String urlLabel = hyperLink;
//build the hyperlink
//file:// ensure that document does not corrupt
System.Uri uri = new Uri(@"file://" + hyperLink);
//add it to the document
HyperlinkRelationship rel = mainDocPart.AddHyperlinkRelationship(uri, true);
//get the hyperlink id
string relationshipId = rel.Id;
//create the new paragraph tag
Paragraph newParagraph = new Paragraph(
new DocumentFormat.OpenXml.Wordprocessing.Hyperlink(
new ProofError() { Type = ProofingErrorValues.GrammarStart },
new DocumentFormat.OpenXml.Wordprocessing.Run(
new DocumentFormat.OpenXml.Wordprocessing.RunProperties(
new RunStyle() { Val = "Hyperlink" }),
new DocumentFormat.OpenXml.Wordprocessing.Text(urlLabel)
)) { History = OnOffValue.FromBoolean(true), Id = relationshipId });
return newParagraph;
}
示例8: RefreshCharts
/// <summary>
/// Refreshes the charts.
/// </summary>
/// <param name="mainDocumentPart">The main document part.</param>
protected override void RefreshCharts(MainDocumentPart mainDocumentPart)
{
if (mainDocumentPart != null)
{
foreach (ChartPart chartPart in mainDocumentPart.ChartParts)
{
Chart chart = chartPart.ChartSpace.Elements<Chart>().FirstOrDefault();
if (chart != null)
{
DocumentFormat.OpenXml.Drawing.Charts.ScatterChart scatterChart = chart.Descendants<DocumentFormat.OpenXml.Drawing.Charts.ScatterChart>().FirstOrDefault();
DocumentFormat.OpenXml.Drawing.Charts.Line3DChart lineChart = chart.Descendants<DocumentFormat.OpenXml.Drawing.Charts.Line3DChart>().FirstOrDefault();
if (scatterChart != null)
{
ScatterChartEx chartEx = new ScatterChartEx(chartPart, this.scatterChartData);
chartEx.Refresh();
}
if (lineChart != null)
{
Line3DChartEx chartEx = new Line3DChartEx(chartPart, this.lineChartData);
chartEx.Refresh();
}
}
chartPart.ChartSpace.Save();
}
}
}
示例9: InsertAfter
public override void InsertAfter(OpenXmlElement openXmlNode, MainDocumentPart mainDocumentPart)
{
_mainDocumentPart = mainDocumentPart;
var imagePart = CreateImagePart();
openXmlNode.InsertAfterSelf(CreateImageElement(mainDocumentPart.GetIdOfPart(imagePart), Path.GetFileName(_content)));
}
示例10: CreateStyles
public static Styles CreateStyles(MainDocumentPart mainPart)
{
StyleDefinitionsPart styleDefinitionsPart = mainPart.AddNewPart<StyleDefinitionsPart>();
Styles styles = new Styles();
styleDefinitionsPart.Styles = styles;
//styles.Save();
return styles;
}
示例11: OpenTheDocuemnt
/// <summary>
/// Open an Word XML document
/// </summary>
/// <param name="docname">name of the document to be opened</param>
public void OpenTheDocuemnt(string docname)
{
// open the word docx
wordProcessingDocument = WordprocessingDocument.Open(docname, true);
// get the Main Document part
mainDocPart = wordProcessingDocument.MainDocumentPart;
}
示例12: AppendTo
public override void AppendTo(OpenXmlElement openXmlNode, MainDocumentPart mainDocumentPart)
{
var text = _newParagraph
? (OpenXmlElement)new Paragraph(new Run(new Text(_content)))
: (OpenXmlElement)new Run(new Text(_content));
openXmlNode.Append(text);
}
示例13: CreateDocument
internal WordprocessingDocument CreateDocument(String fileName)
{
docxFile = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document);
mainPart = docxFile.AddMainDocumentPart();
docxFile.MainDocumentPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document(new Body());
body = docxFile.MainDocumentPart.Document.Body;
return docxFile;
}
示例14: AppendTo
public override void AppendTo(OpenXmlElement openXmlNode, MainDocumentPart mainDocumentPart)
{
var paragraphs = ConvertContentToParagraphs(mainDocumentPart);
foreach (var paragraph in paragraphs)
{
openXmlNode.Append(paragraph);
}
}
示例15: HtmlDocumentStyle
internal HtmlDocumentStyle(MainDocumentPart mainPart)
{
PrepareStyles(mainPart);
tableStyle = new TableStyleCollection(this);
runStyle = new RunStyleCollection(this);
paraStyle = new ParagraphStyleCollection(this);
this.QuoteCharacters = QuoteChars.IE;
this.mainPart = mainPart;
}