Example #1
0
        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();
        }
Example #2
0
 /**
  * Returns the core document properties
  */
 public NPOI.POIXMLProperties.CoreProperties GetCoreProperties()
 {
     return(_document.GetProperties().GetCoreProperties());
 }
Example #3
0
 /**
  * Returns the core document properties
  */
 public CoreProperties GetCoreProperties()
 {
     return(_document.GetProperties().CoreProperties);
 }