本文整理汇总了C#中PartInfo.GetContent方法的典型用法代码示例。如果您正苦于以下问题:C# PartInfo.GetContent方法的具体用法?C# PartInfo.GetContent怎么用?C# PartInfo.GetContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PartInfo
的用法示例。
在下文中一共展示了PartInfo.GetContent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoSomethingToContentPartsRecursively
private void DoSomethingToContentPartsRecursively(OPCPackage package, PartInfo part, PartProcessingDelegate whatToDo)
{
using (Stream data = part.GetContent())
{
whatToDo(data, part);
}
foreach (PartInfo pi in part.GetRelatedObjects())
{
DoSomethingToContentPartsRecursively(package, pi, whatToDo);
}
}
示例2: CreateForWriting
public void CreateForWriting()
{
string fileName = TESTFILE_DIR + "testCreate.docx";
if (File.Exists(fileName))
{
File.Delete(fileName);
}
try
{
using (Stream s = new FileStream(fileName, FileMode.CreateNew))
{
List<DefaultInfo> ldi = new List<DefaultInfo>();
ldi.Add(new DefaultInfo("xls", "application/xml"));
ldi.Add(new DefaultInfo("rels", "application/vnd.openxmlformats-package.relationships+xml"));
using (OPCPackage package = new OPCPackage(s, ldi, OpenXmlFormatDefinition.OpenXmlFormat.Transitional))
{
using (Stream str = File.Open(TESTFILE_DIR + "document1.xml", FileMode.Open))
{
PartInfo rel = new PartInfo(package);
rel.Type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
rel.Id = "rId1";
rel.Target = "/word/document.xml";
rel.RelatedTo = "";
package.AddContent(rel, str, OpenXmlFormatDefinition.OpenXmlFormat.Transitional);
}
}
}
Assert.IsTrue(File.Exists(fileName));
using (OPCPackage readPackage = new OPCPackage(File.Open(fileName, FileMode.Open)))
{
PartInfo rel = readPackage.GetRelatedObjects("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument")[0];
Stream str = rel.GetContent();
Assert.IsNotNull(str, "whoops, no content found");
DocxTestUtilities.ValidateDocxMainStream(str, TESTFILE_DIR);
Assert.AreEqual("word/document.xml", rel.Target);
Assert.AreEqual(2, readPackage.GetDefaultTypes().Count, "Expected the written package to containt eh 2 defaults in the original package");
}
}
finally
{
File.Delete(fileName);
}
}