mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00
Fixes for being able to compile with playground (#380)
This commit is contained in:
parent
72ad869a28
commit
0e183a6e7b
@ -26,10 +26,14 @@ func main() {
|
||||
fmt.Println("Non-existent", cp.GetPropertyByName("nonexistentproperty"))
|
||||
|
||||
// And change them as well
|
||||
cp.SetPropertyAsLpwstr("Company", "Another company") // text, existing property
|
||||
fmt.Println("Company", *cp.GetPropertyByName("Company").Lpwstr)
|
||||
|
||||
// Adding new properties
|
||||
cp.SetPropertyAsLpwstr("Another text property", "My text value") // text
|
||||
cp.SetPropertyAsI4("Another integer number property", 42) // int23
|
||||
cp.SetPropertyAsR8("Another float number property", 3.14) // float64
|
||||
cp.SetPropertyAsDate("Another date property", time.Now()) // date
|
||||
cp.SetPropertyAsI4("Another integer number property", 42) // int32
|
||||
cp.SetPropertyAsR8("Another float number property", 3.14) // float64
|
||||
cp.SetPropertyAsDate("Another date property", time.Now()) // date
|
||||
|
||||
doc.SaveToFile("document_customized.docx")
|
||||
|
||||
@ -38,9 +42,9 @@ func main() {
|
||||
|
||||
cpNew := docNew.GetOrCreateCustomProperties()
|
||||
cpNew.SetPropertyAsLpwstr("Another text property", "My text value") // text
|
||||
cpNew.SetPropertyAsI4("Another integer number property", 42) // int23
|
||||
cpNew.SetPropertyAsR8("Another float number property", 3.14) // float64
|
||||
cpNew.SetPropertyAsDate("Another date property", time.Now()) // date
|
||||
cpNew.SetPropertyAsI4("Another integer number property", 42) // int23
|
||||
cpNew.SetPropertyAsR8("Another float number property", 3.14) // float64
|
||||
cpNew.SetPropertyAsDate("Another date property", time.Now()) // date
|
||||
|
||||
docNew.SaveToFile("document_new.docx")
|
||||
}
|
||||
|
@ -37,10 +37,18 @@ func (c CustomProperties) PropertiesList() []*custom_properties.CT_Property {
|
||||
}
|
||||
|
||||
func (c CustomProperties) GetPropertyByName(name string) CustomProperty {
|
||||
property := c.getPropertyByName(name)
|
||||
if property == nil {
|
||||
return nil
|
||||
}
|
||||
return CustomProperty(property)
|
||||
}
|
||||
|
||||
func (c CustomProperties) getPropertyByName(name string) *custom_properties.CT_Property {
|
||||
propsList := c.x.Property
|
||||
for _, property := range propsList {
|
||||
if *property.NameAttr == name {
|
||||
return CustomProperty(property)
|
||||
return property
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -61,7 +69,7 @@ func (c CustomProperties) getNewProperty(name string) *custom_properties.CT_Prop
|
||||
}
|
||||
|
||||
func (c CustomProperties) setProperty(newProperty *custom_properties.CT_Property) {
|
||||
existingProperty := c.GetPropertyByName(*newProperty.NameAttr)
|
||||
existingProperty := c.getPropertyByName(*newProperty.NameAttr)
|
||||
if existingProperty == nil {
|
||||
c.x.Property = append(c.x.Property, newProperty)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user