本文整理汇总了C#中NPOI.OpenXml4Net.OPC.OPCPackage类的典型用法代码示例。如果您正苦于以下问题:C# OPCPackage类的具体用法?C# OPCPackage怎么用?C# OPCPackage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OPCPackage类属于NPOI.OpenXml4Net.OPC命名空间,在下文中一共展示了OPCPackage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clone
/**
* Clone the specified namespace.
*
* @param pkg the namespace to clone
* @param file the destination file
* @return the Cloned namespace
*/
public static OPCPackage Clone(OPCPackage pkg, string path)
{
OPCPackage dest = OPCPackage.Create(path);
PackageRelationshipCollection rels = pkg.Relationships;
foreach (PackageRelationship rel in rels)
{
PackagePart part = pkg.GetPart(rel);
PackagePart part_tgt;
if (rel.RelationshipType.Equals(PackageRelationshipTypes.CORE_PROPERTIES))
{
CopyProperties(pkg.GetPackageProperties(), dest.GetPackageProperties());
continue;
}
dest.AddRelationship(part.PartName, (TargetMode)rel.TargetMode, rel.RelationshipType);
part_tgt = dest.CreatePart(part.PartName, part.ContentType);
Stream out1 = part_tgt.GetOutputStream();
IOUtils.Copy(part.GetInputStream(), out1);
out1.Close();
if (part.HasRelationships)
{
Copy(pkg, part, dest, part_tgt);
}
}
dest.Close();
//the temp file will be deleted when JVM terminates
//new File(path).deleteOnExit();
return OPCPackage.Open(path);
}
示例2: POIXMLDocumentPart
/**
* Construct POIXMLDocumentPart representing a "core document" namespace part.
*/
public POIXMLDocumentPart(OPCPackage pkg)
{
PackageRelationship coreRel = pkg.GetRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).GetRelationship(0);
this.packagePart = pkg.GetPart(coreRel);
this.packageRel = coreRel;
}
示例3: XWPFDocument
public XWPFDocument(OPCPackage pkg)
: base(pkg)
{
;
//build a tree of POIXMLDocumentParts, this document being the root
Load(XWPFFactory.GetInstance());
}
示例4: XSSFEventBasedExcelExtractor
public XSSFEventBasedExcelExtractor(OPCPackage Container)
: base(null)
{
this.Container = Container;
properties = new POIXMLProperties(Container);
}
示例5: GetTargetPart
/**
* Get the PackagePart that is the target of a relationship.
*
* @param rel The relationship
* @param pkg The namespace to fetch from
* @return The target part
* @throws InvalidFormatException
*/
protected static PackagePart GetTargetPart(OPCPackage pkg, PackageRelationship rel)
{
PackagePartName relName = PackagingUriHelper.CreatePartName(rel.TargetUri);
PackagePart part = pkg.GetPart(relName);
if (part == null) {
throw new ArgumentException("No part found for relationship " + rel);
}
return part;
}
示例6: PackagePart
/**
* Constructor.
*
* @param pack
* Parent package.
* @param partName
* The part name, relative to the parent Package root.
* @param contentType
* The content type.
* @param loadRelationships
* Specify if the relationships will be loaded
* @throws InvalidFormatException
* If the specified URI is not valid.
*/
protected PackagePart(OPCPackage pack, PackagePartName partName,
ContentType contentType, bool loadRelationships)
{
this.partName = partName;
this.contentType = contentType;
this.container = (ZipPackage)pack; // TODO - enforcing ZipPackage here - perhaps should change constructor signature
// Check if this part is a relationship part
isRelationshipPart = this.partName.IsRelationshipPartURI();
// Load relationships if any
if (loadRelationships)
LoadRelationships();
}
示例7: POIXMLDocumentPart
/**
* Construct POIXMLDocumentPart representing a "core document" namespace part.
*/
public POIXMLDocumentPart(OPCPackage pkg)
{
PackageRelationship coreRel = pkg.GetRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).GetRelationship(0);
if (coreRel == null)
{
coreRel = pkg.GetRelationshipsByType(PackageRelationshipTypes.STRICT_CORE_DOCUMENT).GetRelationship(0);
if (coreRel != null)
{
throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
}
}
if (coreRel == null)
{
throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
}
this.packagePart = pkg.GetPart(coreRel);
this.packageRel = coreRel;
}
示例8: AssertReadWrite
public void AssertReadWrite(OPCPackage pkg1)
{
OPCParser doc = new OPCParser(pkg1);
doc.Parse(new TestFactory());
Dictionary<String, POIXMLDocumentPart> context = new Dictionary<String, POIXMLDocumentPart>();
Traverse(doc, context);
context.Clear();
string tmp = TempFile.GetTempFilePath("poi-ooxml", ".tmp");
FileStream out1 = new FileStream(tmp, FileMode.CreateNew);
doc.Write(out1);
out1.Close();
OPCPackage pkg2 = OPCPackage.Open(tmp);
doc = new OPCParser(pkg1);
doc.Parse(new TestFactory());
context = new Dictionary<String, POIXMLDocumentPart>();
Traverse(doc, context);
context.Clear();
Assert.AreEqual(pkg1.Relationships.Size, pkg2.Relationships.Size);
List<PackagePart> l1 = pkg1.GetParts();
List<PackagePart> l2 = pkg2.GetParts();
Assert.AreEqual(l1.Count, l2.Count);
for (int i = 0; i < l1.Count; i++)
{
PackagePart p1 = l1[i];
PackagePart p2 = l2[i];
Assert.AreEqual(p1.ContentType, p2.ContentType);
Assert.AreEqual(p1.HasRelationships, p2.HasRelationships);
if (p1.HasRelationships)
{
Assert.AreEqual(p1.Relationships.Size, p2.Relationships.Size);
}
Assert.AreEqual(p1.PartName, p2.PartName);
}
}
示例9: PackageRelationship
/**
* Constructor.
*
* @param pkg
* @param sourcePart
* @param targetUri
* @param targetMode
* @param relationshipType
* @param id
*/
public PackageRelationship(OPCPackage pkg, PackagePart sourcePart,
Uri targetUri, TargetMode targetMode, String relationshipType,
String id)
{
if (pkg == null)
throw new ArgumentException("pkg");
if (targetUri == null)
throw new ArgumentException("targetUri");
if (relationshipType == null)
throw new ArgumentException("relationshipType");
if (id == null)
throw new ArgumentException("id");
this.container = pkg;
this.source = sourcePart;
this.targetUri = targetUri;
this.targetMode = targetMode;
this.relationshipType = relationshipType;
this.id = id;
}
示例10: POIXMLProperties
public POIXMLProperties(OPCPackage docPackage)
{
this.pkg = docPackage;
// Core properties
core = new CoreProperties((PackagePropertiesPart)pkg.GetPackageProperties());
// Extended properties
PackageRelationshipCollection extRel =
pkg.GetRelationshipsByType(PackageRelationshipTypes.EXTENDED_PROPERTIES);
if (extRel.Size == 1)
{
extPart = pkg.GetPart(extRel.GetRelationship(0));
ExtendedPropertiesDocument props = ExtendedPropertiesDocument.Parse(
extPart.GetInputStream()
);
ext = new ExtendedProperties(props);
}
else
{
extPart = null;
ext = new ExtendedProperties((ExtendedPropertiesDocument)NEW_EXT_INSTANCE.Copy());
}
// Custom properties
PackageRelationshipCollection custRel =
pkg.GetRelationshipsByType(PackageRelationshipTypes.CUSTOM_PROPERTIES);
if (custRel.Size == 1)
{
custPart = pkg.GetPart(custRel.GetRelationship(0));
CustomPropertiesDocument props = CustomPropertiesDocument.Parse(
custPart.GetInputStream()
);
cust = new CustomProperties(props);
}
else
{
custPart = null;
cust = new CustomProperties((CustomPropertiesDocument)NEW_CUST_INSTANCE.Copy());
}
}
示例11: Assert_50154
public void Assert_50154(OPCPackage pkg)
{
Uri drawingUri = new Uri("/xl/drawings/drawing1.xml",UriKind.Relative);
PackagePart drawingPart = pkg.GetPart(PackagingUriHelper.CreatePartName(drawingUri));
PackageRelationshipCollection drawingRels = drawingPart.Relationships;
Assert.AreEqual(6, drawingRels.Size);
// expected one image
Assert.AreEqual(1, drawingPart.GetRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image").Size);
// and three hyperlinks
Assert.AreEqual(5, drawingPart.GetRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink").Size);
PackageRelationship rId1 = drawingPart.GetRelationship("rId1");
Uri parent = drawingPart.PartName.URI;
Uri rel1 = new Uri(Path.Combine(parent.ToString(),rId1.TargetUri.ToString()),UriKind.Relative);
Uri rel11 = PackagingUriHelper.RelativizeUri(drawingPart.PartName.URI, rId1.TargetUri);
Assert.AreEqual("#'Another Sheet'!A1", HttpUtility.UrlDecode(rel1.ToString().Split(new char[]{'/'})[3]));
PackageRelationship rId2 = drawingPart.GetRelationship("rId2");
Uri rel2 = PackagingUriHelper.RelativizeUri(drawingPart.PartName.URI, rId2.TargetUri);
Assert.AreEqual("../media/image1.png", rel2.OriginalString);
PackageRelationship rId3 = drawingPart.GetRelationship("rId3");
Uri rel3 = new Uri(Path.Combine(parent.ToString(), rId3.TargetUri.ToString()), UriKind.Relative);
Assert.AreEqual("#ThirdSheet!A1", rel3.OriginalString.Split(new char[] { '/' })[3]);
PackageRelationship rId4 = drawingPart.GetRelationship("rId4");
Uri rel4 = new Uri(Path.Combine(parent.ToString(), rId4.TargetUri.ToString()), UriKind.Relative);
Assert.AreEqual("#'\u0410\u043F\u0430\u0447\u0435 \u041F\u041E\u0418'!A1",HttpUtility.UrlDecode(rel4.OriginalString.Split(new char[] { '/' })[3]));
//PackageRelationship rId5 = drawingPart.GetRelationship("rId5");
//Uri rel5 = new Uri(Path.Combine(parent.ToString(), rId5.TargetUri.ToString()), UriKind.Relative);
//// back slashed have been Replaced with forward
//Assert.AreEqual("file:///D:/chan-chan.mp3", rel5.ToString());
//PackageRelationship rId6 = drawingPart.GetRelationship("rId6");
//Uri rel6 = new Uri(ResolveRelativePath(parent.ToString(), HttpUtility.UrlDecode(rId6.TargetUri.ToString())), UriKind.Relative);
//Assert.AreEqual("../../../../../../../cygwin/home/yegor/dinom/&&&[access].2010-10-26.log", rel6.OriginalString);
//Assert.AreEqual("#'\u0410\u043F\u0430\u0447\u0435 \u041F\u041E\u0418'!A5", HttpUtility.UrlDecode(rel6.OriginalString.Split(new char[] { '/' })[3]));
}
示例12: Rebase
/**
* When you open something like a theme, call this to
* re-base the XML Document onto the core child of the
* current core document
*/
protected void Rebase(OPCPackage pkg)
{
PackageRelationshipCollection cores =
packagePart.GetRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
if (cores.Size != 1)
{
throw new InvalidOperationException(
"Tried to rebase using " + PackageRelationshipTypes.CORE_DOCUMENT +
" but found " + cores.Size + " parts of the right type"
);
}
packageRel = cores.GetRelationship(0);
packagePart = packagePart.GetRelatedPart(packageRel);
}
示例13: XSSFWorkbook
/**
* Constructs a XSSFWorkbook object given a OpenXML4J <code>Package</code> object,
* see <a href="http://poi.apache.org/oxml4j/">http://poi.apache.org/oxml4j/</a>.
*
* Once you have finished working with the Workbook, you should close the package
* by calling pkg.close, to avoid leaving file handles open.
*
* Creating a XSSFWorkbook from a file-backed OPC Package has a lower memory
* footprint than an InputStream backed one.
*
* @param pkg the OpenXML4J <code>OPC Package</code> object.
*/
public XSSFWorkbook(OPCPackage pkg)
: base(pkg)
{
//build a tree of POIXMLDocumentParts, this workbook being the root
Load(XSSFFactory.GetInstance());
}
示例14: ZipPackagePart
/**
* Constructor.
*
* @param container
* The container package.
* @param partName
* Part name.
* @param contentType
* Content type.
* @throws InvalidFormatException
* Throws if the content of this part invalid.
*/
public ZipPackagePart(OPCPackage container, PackagePartName partName,
String contentType):base(container, partName, contentType)
{
}
示例15: PackagePropertiesPart
/**
* Constructor.
*
* @param pack
* Container package.
* @param partName
* Name of this part.
* @throws InvalidFormatException
* Throws if the content is invalid.
*/
public PackagePropertiesPart(OPCPackage pack, PackagePartName partName)
:base(pack, partName, ContentTypes.CORE_PROPERTIES_PART)
{
}