/** * Creates a new text extractor for the given document */ public POIXMLTextExtractor(POIXMLDocument document) : base((POIDocument)null) { _document = document; }
/* [Test] public void TestPowerPoint() { POIXMLDocument doc = new XSLFSlideShow(OPCPackage.Open( POIDataSamples.GetSlideShowInstance().OpenResourceAsStream("PPTWithAttachments.pptm")) ); Test(doc, 4); }*/ private void Test(POIXMLDocument doc, int expectedCount) { Assert.IsNotNull(doc.GetAllEmbedds()); Assert.AreEqual(expectedCount, doc.GetAllEmbedds().Count); for (int i = 0; i < doc.GetAllEmbedds().Count; i++) { PackagePart pp = doc.GetAllEmbedds()[i]; Assert.IsNotNull(pp); byte[] b = IOUtils.ToByteArray(pp.GetStream(System.IO.FileMode.Open)); Assert.IsTrue(b.Length > 0); } }
/* * [Test] * public void TestPowerPoint() * { * POIXMLDocument doc = new XSLFSlideShow(OPCPackage.Open( * POIDataSamples.GetSlideShowInstance().OpenResourceAsStream("PPTWithAttachments.pptm")) * ); * Test(doc, 4); * }*/ private void Test(POIXMLDocument doc, int expectedCount) { Assert.IsNotNull(doc.GetAllEmbedds()); Assert.AreEqual(expectedCount, doc.GetAllEmbedds().Count); for (int i = 0; i < doc.GetAllEmbedds().Count; i++) { PackagePart pp = doc.GetAllEmbedds()[i]; Assert.IsNotNull(pp); byte[] b = IOUtils.ToByteArray(pp.GetStream(System.IO.FileMode.Open)); Assert.IsTrue(b.Length > 0); } }
/** * 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 = POIXMLDocument.GetTargetPart(pkg, packageRel); }
public POIXMLTextExtractor(POIXMLDocument document) : base((POIDocument)null) { this._document = document; }
/** * Creates a new POIXMLPropertiesTextExtractor for the * given open document. */ public POIXMLPropertiesTextExtractor(POIXMLDocument doc) : base(doc) { }
public void TestCustomProperties() { POIXMLDocument wb1 = new XSSFWorkbook(); CustomProperties customProps = wb1.GetProperties().CustomProperties; customProps.AddProperty("test-1", "string val"); customProps.AddProperty("test-2", 1974); customProps.AddProperty("test-3", 36.6); //Adding a duplicate try { customProps.AddProperty("test-3", 36.6); Assert.Fail("expected exception"); } catch (ArgumentException e) { Assert.AreEqual("A property with this name already exists in the custom properties", e.Message); } customProps.AddProperty("test-4", true); POIXMLDocument wb2 = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack((XSSFWorkbook)wb1); wb1.Close(); CT_CustomProperties ctProps = wb2.GetProperties().CustomProperties.GetUnderlyingProperties(); Assert.AreEqual(6, ctProps.sizeOfPropertyArray()); CT_Property p; p = ctProps.GetPropertyArray(0); Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid); Assert.AreEqual("test-1", p.name); Assert.AreEqual("string val", p.Item.ToString()); Assert.AreEqual(2, p.pid); p = ctProps.GetPropertyArray(1); Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid); Assert.AreEqual("test-2", p.name); Assert.AreEqual(1974, p.Item); Assert.AreEqual(3, p.pid); p = ctProps.GetPropertyArray(2); Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid); Assert.AreEqual("test-3", p.name); Assert.AreEqual(36.6, p.Item); Assert.AreEqual(4, p.pid); p = ctProps.GetPropertyArray(3); Assert.AreEqual("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.fmtid); Assert.AreEqual("test-4", p.name); Assert.AreEqual(true, p.Item); Assert.AreEqual(5, p.pid); p = ctProps.GetPropertyArray(4); Assert.AreEqual("Generator", p.name); Assert.AreEqual("NPOI", p.Item); Assert.AreEqual(6, p.pid); //p = ctProps.GetPropertyArray(5); //Assert.AreEqual("Generator Version", p.name); //Assert.AreEqual("2.0.9", p.Item); //Assert.AreEqual(7, p.pid); wb2.Close(); }
/** * Creates a new text extractor for the given document */ public POIXMLTextExtractor(POIXMLDocument document) { _document = document; }