本文整理汇总了C#中OpenXmlPart类的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlPart类的具体用法?C# OpenXmlPart怎么用?C# OpenXmlPart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OpenXmlPart类属于命名空间,在下文中一共展示了OpenXmlPart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenXmlPartRootElement
/// <summary>
/// Initializes a new instance of the OpenXmlPartRootElement class using the supplied OpenXmlPart.
/// </summary>
/// <param name="openXmlPart">The OpenXmlPart class.</param>
protected OpenXmlPartRootElement(OpenXmlPart openXmlPart)
{
if (openXmlPart == null)
{
throw new ArgumentNullException("openXmlPart");
}
this._elementContext = new OpenXmlElementContext();
LoadFromPart(openXmlPart);
}
示例2: ImageData
public ImageData(OpenXmlPart contentPart, ImagePart part)
{
ContentType = part.ContentType;
ContentPart = contentPart;
using (Stream s = part.GetStream(FileMode.Open, FileAccess.Read))
{
Image = new byte[s.Length];
s.Read(Image, 0, (int)s.Length);
}
}
示例3: LoadPart
private XDocument LoadPart(OpenXmlPart source)
{
if (source == null) return null;
var part = source.Annotation<XDocument>();
if (part != null) return part;
using (var str = source.GetStream())
using (var streamReader = new StreamReader(str))
using (var xr = XmlReader.Create(streamReader))
part = XDocument.Load(xr);
return part;
}
示例4: ProcessTemplatePart
private static void ProcessTemplatePart(XElement data, TemplateError te, OpenXmlPart part)
{
XDocument xDoc = part.GetXDocument();
XElement newRootElementWithMetadata = (XElement)TransformToMetadata(xDoc.Root, data, te);
NormalizeTablesRepeatAndConditional(newRootElementWithMetadata, te);
XElement newRootElement = newRootElementWithMetadata;
// do the actual content replacement
newRootElement = (XElement)ContentReplacementTransform(newRootElement, data, te);
xDoc.Elements().First().ReplaceWith(newRootElement);
part.PutXDocument();
return;
}
示例5: WriteElementToCustomXmlPart
/// <summary>
/// Writes the element to custom XML part.
/// </summary>
/// <param name="customXmlPart">The custom XML part.</param>
/// <param name="rootElement">The root element.</param>
public static void WriteElementToCustomXmlPart(OpenXmlPart customXmlPart, XNode rootElement)
{
if (customXmlPart == null)
{
throw new ArgumentNullException("customXmlPart");
}
if (rootElement == null)
{
throw new ArgumentNullException("rootElement");
}
using (var writer = XmlWriter.Create(customXmlPart.GetStream(FileMode.Create, FileAccess.Write)))
{
rootElement.WriteTo(writer);
writer.Flush();
}
}
示例6: FlushPart
private static void FlushPart(OpenXmlPart part, HashSet<OpenXmlPart> visited)
{
visited.Add(part);
XDocument xdoc = part.Annotation<XDocument>();
if (xdoc != null && xdoc.Annotation<ChangedSemaphore>() != null)
{
using (XmlWriter xw = XmlWriter.Create(part.GetStream(FileMode.Create, FileAccess.Write)))
{
xdoc.Save(xw);
}
xdoc.RemoveAnnotations<ChangedSemaphore>();
xdoc.Changing += ElementChanged;
xdoc.Changed += ElementChanged;
}
foreach (IdPartPair item in part.Parts)
if (!visited.Contains(item.OpenXmlPart))
FlushPart(item.OpenXmlPart, visited);
}
示例7: AcceptRevisionsForPart
public static void AcceptRevisionsForPart(OpenXmlPart part)
{
XElement documentElement = part.GetXDocument().Root;
documentElement = (XElement)AcceptMoveFromMoveToTransform(documentElement);
documentElement = AcceptMoveFromRanges(documentElement);
// AcceptParagraphEndTagsInMoveFromTransform needs rewritten similar to AcceptDeletedAndMoveFromParagraphMarks
documentElement = (XElement)AcceptParagraphEndTagsInMoveFromTransform(documentElement);
documentElement = AcceptDeletedAndMovedFromContentControls(documentElement);
documentElement = AcceptDeletedAndMoveFromParagraphMarks(documentElement);
documentElement = (XElement)RemoveRowsLeftEmptyByMoveFrom(documentElement);
documentElement = (XElement)AcceptAllOtherRevisionsTransform(documentElement);
documentElement = (XElement)AcceptDeletedCellsTransform(documentElement);
documentElement = (XElement)MergeAdjacentTablesTransform(documentElement);
documentElement.Descendants().Attributes().Where(a => a.Name == PT.UniqueId || a.Name == PT.RunIds).Remove();
documentElement.Descendants(W.numPr).Where(np => !np.HasElements).Remove();
XDocument newXDoc = new XDocument(documentElement);
part.PutXDocument(newXDoc);
}
示例8: PartHasTrackedRevisions
public bool PartHasTrackedRevisions(OpenXmlPart part)
{
XmlDocument doc = GetXmlDocument(part);
string wordNamespace =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main";
XmlNamespaceManager nsmgr =
new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("w", wordNamespace);
string xpathExpression =
"descendant::w:cellDel|" +
"descendant::w:cellIns|" +
"descendant::w:cellMerge|" +
"descendant::w:customXmlDelRangeEnd|" +
"descendant::w:customXmlDelRangeStart|" +
"descendant::w:customXmlInsRangeEnd|" +
"descendant::w:customXmlInsRangeStart|" +
"descendant::w:del|" +
"descendant::w:delInstrText|" +
"descendant::w:delText|" +
"descendant::w:ins|" +
"descendant::w:moveFrom|" +
"descendant::w:moveFromRangeEnd|" +
"descendant::w:moveFromRangeStart|" +
"descendant::w:moveTo|" +
"descendant::w:moveToRangeEnd|" +
"descendant::w:moveToRangeStart|" +
"descendant::w:moveTo|" +
"descendant::w:numberingChange|" +
"descendant::w:rPrChange|" +
"descendant::w:pPrChange|" +
"descendant::w:rPrChange|" +
"descendant::w:sectPrChange|" +
"descendant::w:tcPrChange|" +
"descendant::w:tblGridChange|" +
"descendant::w:tblPrChange|" +
"descendant::w:tblPrExChange|" +
"descendant::w:trPrChange";
XmlNodeList descendants = doc.SelectNodes(xpathExpression, nsmgr);
return descendants.Count > 0;
}
示例9: Create
/// <summary>
/// Creates an OpenXmlReader from the specified OpenXmlPart and Boolean values.
/// </summary>
/// <param name="openXmlPart">The OpenXmlPart to read.</param>
/// <param name="readMiscNodes">Specify false to indicate to the reader to skip all miscellaneous nodes. The default value is false.</param>
/// <returns>The newly created OpenXmlReader.</returns>
public static OpenXmlReader Create(OpenXmlPart openXmlPart, bool readMiscNodes)
{
return new OpenXmlPartReader(openXmlPart, readMiscNodes);
}
示例10: XmlPath
/// <summary>
/// Initlizes a new instance of the XmlPath from the specified OpenXmlPart.
/// </summary>
/// <param name="part">The OpenXmlPart.</param>
internal XmlPath(OpenXmlPart part)
{
Debug.Assert(part != null);
this.PartUri = part.Uri;
}
示例11: OpenXmlPartReader
/// <summary>
/// Initializes a new instance of the OpenXmlPartReader class using the supplied OpenXmlPart and Boolean values.
/// </summary>
/// <param name="openXmlPart">The OpenXmlPart to read.</param>
/// <param name="readMiscNodes">Specify false to indicate to the reader to skip all miscellaneous nodes. The default value is false.</param>
public OpenXmlPartReader(OpenXmlPart openXmlPart, bool readMiscNodes)
: this(readMiscNodes)
{
if (openXmlPart == null)
{
throw new ArgumentNullException("openXmlPart");
}
// set MaxCharactersInDocument to limit the part size on loading DOM.
this._elementContext.XmlReaderSettings.MaxCharactersInDocument = openXmlPart.MaxCharactersInPart;
Stream partStream = openXmlPart.GetStream(FileMode.Open);
this.Init(partStream, /*closeInput*/true);
}
示例12: GenerateImagePart
private static void GenerateImagePart(OpenXmlPart part, byte[] imageFileBytes)
{
// Write the contents of the image to the ImagePart.
using (BinaryWriter writer = new BinaryWriter(part.GetStream()))
{
writer.Write(imageFileBytes);
writer.Flush();
}
}
示例13: AddPart
private static void AddPart(HashSet<OpenXmlPart> partList, OpenXmlPart part)
{
if (partList.Contains(part))
return;
partList.Add(part);
foreach (IdPartPair p in part.Parts)
AddPart(partList, p.OpenXmlPart);
}
示例14: AddContentPartRelTypeResourceIdTupple
public void AddContentPartRelTypeResourceIdTupple(OpenXmlPart contentPart, string relationshipType, string relationshipId)
{
ContentPartRelTypeIdList.Add(
new ContentPartRelTypeIdTuple()
{
ContentPart = contentPart,
RelationshipType = relationshipType,
RelationshipId = relationshipId,
});
}
示例15: MergeCommentsInPart
private static void MergeCommentsInPart(OpenXmlPart part1, OpenXmlPart part2,
OpenXmlPart destinationPart, XDocument commentsPartXDoc)
{
XDocument xdoc1 = part1.GetXDocument();
XDocument xdoc2 = part2.GetXDocument();
XElement newRootElement = (XElement)MergeElementTransform(xdoc1.Root, xdoc2.Root,
commentsPartXDoc);
destinationPart.PutXDocument(new XDocument(newRootElement));
}