public void TestCustomProperties() { POIXMLDocument wb = new XSSFWorkbook(); POIXMLProperties.CustomProperties customProps = wb.GetProperties().GetCustomProperties(); 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); wb = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack((XSSFWorkbook)wb); CT_CustomProperties ctProps = wb.GetProperties().GetCustomProperties().GetUnderlyingProperties(); Assert.AreEqual(4, 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); }
/** * Returns the custom document properties, if * there are any */ public String GetCustomPropertiesText() { StringBuilder text = new StringBuilder(); CT_CustomProperties props = Document.GetProperties().GetCustomProperties().GetUnderlyingProperties(); List <CT_Property> properties = props.GetPropertyList(); for (int i = 0; i < properties.Count; i++) { // TODO - finish off String val = "(not implemented!)"; text.Append( properties[i].name + " = " + val + "\n" ); } return(text.ToString()); }
public static CT_Worksheet Parse(XmlNode node, XmlNamespaceManager namespaceManager) { if (node == null) { return(null); } CT_Worksheet ctObj = new CT_Worksheet(); ctObj.cols = new List <CT_Cols>(); ctObj.conditionalFormatting = new List <CT_ConditionalFormatting>(); foreach (XmlNode childNode in node.ChildNodes) { if (childNode.LocalName == "sheetPr") { ctObj.sheetPr = CT_SheetPr.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "dimension") { ctObj.dimension = CT_SheetDimension.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "sheetViews") { ctObj.sheetViews = CT_SheetViews.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "sheetFormatPr") { ctObj.sheetFormatPr = CT_SheetFormatPr.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "sheetData") { ctObj.sheetData = CT_SheetData.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "sheetCalcPr") { ctObj.sheetCalcPr = CT_SheetCalcPr.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "sheetProtection") { ctObj.sheetProtection = CT_SheetProtection.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "protectedRanges") { ctObj.protectedRanges = CT_ProtectedRanges.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "scenarios") { ctObj.scenarios = CT_Scenarios.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "autoFilter") { ctObj.autoFilter = CT_AutoFilter.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "sortState") { ctObj.sortState = CT_SortState.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "dataConsolidate") { ctObj.dataConsolidate = CT_DataConsolidate.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "customSheetViews") { ctObj.customSheetViews = CT_CustomSheetViews.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "mergeCells") { ctObj.mergeCells = CT_MergeCells.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "phoneticPr") { ctObj.phoneticPr = CT_PhoneticPr.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "dataValidations") { ctObj.dataValidations = CT_DataValidations.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "hyperlinks") { ctObj.hyperlinks = CT_Hyperlinks.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "printOptions") { ctObj.printOptions = CT_PrintOptions.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "pageMargins") { ctObj.pageMargins = CT_PageMargins.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "pageSetup") { ctObj.pageSetup = CT_PageSetup.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "headerFooter") { ctObj.headerFooter = CT_HeaderFooter.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "rowBreaks") { ctObj.rowBreaks = CT_PageBreak.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "colBreaks") { ctObj.colBreaks = CT_PageBreak.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "customProperties") { ctObj.customProperties = CT_CustomProperties.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "cellWatches") { ctObj.cellWatches = CT_CellWatches.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "ignoredErrors") { ctObj.ignoredErrors = CT_IgnoredErrors.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "smartTags") { ctObj.smartTags = CT_CellSmartTags.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "drawing") { ctObj.drawing = CT_Drawing.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "legacyDrawing") { ctObj.legacyDrawing = CT_LegacyDrawing.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "legacyDrawingHF") { ctObj.legacyDrawingHF = CT_LegacyDrawing.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "picture") { ctObj.picture = CT_SheetBackgroundPicture.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "oleObjects") { ctObj.oleObjects = CT_OleObjects.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "controls") { ctObj.controls = CT_Controls.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "webPublishItems") { ctObj.webPublishItems = CT_WebPublishItems.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "tableParts") { ctObj.tableParts = CT_TableParts.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "extLst") { ctObj.extLst = CT_ExtensionList.Parse(childNode, namespaceManager); } else if (childNode.LocalName == "cols") { ctObj.cols.Add(CT_Cols.Parse(childNode, namespaceManager)); } else if (childNode.LocalName == "conditionalFormatting") { ctObj.conditionalFormatting.Add(CT_ConditionalFormatting.Parse(childNode, namespaceManager)); } } return(ctObj); }
/** * Returns the custom document properties, if * there are any */ public String GetCustomPropertiesText() { StringBuilder text = new StringBuilder(); CT_CustomProperties props = Document.GetProperties().CustomProperties.GetUnderlyingProperties(); List <CT_Property> properties = props.GetPropertyList(); foreach (CT_Property property in properties) { String val = "(not implemented!)"; //val = property.Item.ToString(); //if (property.IsSetLpwstr()) //{ // val = property.GetLpwstr(); //} //else if (property.IsSetLpstr()) //{ // val = property.GetLpstr(); //} //else if (property.IsSetDate()) //{ // val = property.GetDate().toString(); //} //else if (property.IsSetFiletime()) //{ // val = property.GetFiletime().toString(); //} //else if (property.IsSetBool()) //{ // val = Boolean.toString(property.GetBool()); //} //// Integers //else if (property.IsSetI1()) //{ // val = Integer.toString(property.GetI1()); //} //else if (property.IsSetI2()) //{ // val = Integer.toString(property.GetI2()); //} //else if (property.IsSetI4()) //{ // val = Integer.toString(property.GetI4()); //} //else if (property.IsSetI8()) //{ // val = Long.toString(property.GetI8()); //} //else if (property.IsSetInt()) //{ // val = Integer.toString(property.GetInt()); //} //// Unsigned Integers //else if (property.IsSetUi1()) //{ // val = Integer.toString(property.GetUi1()); //} //else if (property.IsSetUi2()) //{ // val = Integer.toString(property.GetUi2()); //} //else if (property.IsSetUi4()) //{ // val = Long.toString(property.GetUi4()); //} //else if (property.IsSetUi8()) //{ // val = property.GetUi8().toString(); //} //else if (property.IsSetUint()) //{ // val = Long.toString(property.GetUint()); //} //// Reals //else if (property.IsSetR4()) //{ // val = Float.toString(property.GetR4()); //} //else if (property.IsSetR8()) //{ // val = Double.toString(property.GetR8()); //} //else if (property.IsSetDecimal()) //{ // BigDecimal d = property.GetDecimal(); // if (d == null) // { // val = null; // } // else // { // val = d.toPlainString(); // } //} //else if (property.IsSetArray()) //{ // // TODO Fetch the array values and output //} //else if (property.IsSetVector()) //{ // // TODO Fetch the vector values and output //} //else if (property.IsSetBlob() || property.IsSetOblob()) //{ // // TODO Decode, if possible //} //else if (property.IsSetStream() || property.IsSetOstream() || // property.IsSetVstream()) //{ // // TODO Decode, if possible //} //else if (property.IsSetStorage() || property.IsSetOstorage()) //{ // // TODO Decode, if possible //} text.Append( property.name + " = " + val + "\n" ); } return(text.ToString()); }
/** * Returns the custom document properties, if * there are any */ public String GetCustomPropertiesText() { if (Document == null) { // event based extractor does not have a document return(""); } StringBuilder text = new StringBuilder(); CT_CustomProperties props = Document.GetProperties().CustomProperties.GetUnderlyingProperties(); List <CT_Property> properties = props.GetPropertyList(); foreach (CT_Property property in properties) { String val = "(not implemented!)"; //val = property.Item.ToString(); if (property.IsSetLpwstr()) { val = property.GetLpwstr(); } else if (property.IsSetLpstr()) { val = property.GetLpstr(); } else if (property.IsSetDate()) { val = property.GetDate().ToString(); } else if (property.IsSetFiletime()) { val = property.GetFiletime().ToString(); } else if (property.IsSetBool()) { val = property.GetBool().ToString(); } // Integers else if (property.IsSetI1()) { val = property.GetI1().ToString(); } else if (property.IsSetI2()) { val = property.GetI2().ToString(); } else if (property.IsSetI4()) { val = property.GetI4().ToString(); } else if (property.IsSetI8()) { val = property.GetI8().ToString(); } else if (property.IsSetInt()) { val = property.GetInt().ToString(); } // Unsigned Integers else if (property.IsSetUi1()) { val = property.GetUi1().ToString(); } else if (property.IsSetUi2()) { val = property.GetUi2().ToString(); } else if (property.IsSetUi4()) { val = property.GetUi4().ToString(); } else if (property.IsSetUi8()) { val = property.GetUi8().ToString(); } else if (property.IsSetUint()) { val = property.GetUint().ToString(); } // Reals else if (property.IsSetR4()) { val = property.GetR4().ToString(); } else if (property.IsSetR8()) { val = property.GetR8().ToString(); } else if (property.IsSetDecimal()) { Decimal?d = property.GetDecimal(); if (d == null) { val = null; } else { val = d.ToString(); } } //else if (property.IsSetArray()) //{ // // TODO Fetch the array values and output //} //else if (property.IsSetVector()) //{ // // TODO Fetch the vector values and output //} //else if (property.IsSetBlob() || property.IsSetOblob()) //{ // // TODO Decode, if possible //} //else if (property.IsSetStream() || property.IsSetOstream() || // property.IsSetVstream()) //{ // // TODO Decode, if possible //} //else if (property.IsSetStorage() || property.IsSetOstorage()) //{ // // TODO Decode, if possible //} text.Append( property.name + " = " + val + "\n" ); } return(text.ToString()); }