wordpress hit counter
how to update custom properties of an existing document? - SpreadsheetML - Formats - OpenXML Developer

how to update custom properties of an existing document?

Formats

Discussions about working with different Open XML Formats

how to update custom properties of an existing document?

  • rated by 0 users
  • This post has 1 Reply |
  • 1 Follower
  • I want to use the OpenXML library to update the value of a custom document property.

    I can read and see the custom properties, and maybe even update the value of one of them, but can't quite see how to get it to save back.

                    using (var xl = SpreadsheetDocument.Open(filePath, true))
                    {
                        Console.WriteLine(xl.CustomFilePropertiesPart.Properties.OuterXml);
                        var property = xl.CustomFilePropertiesPart.Properties.GetFirstChild<Property>();
                        Console.WriteLine("Property {0} = {1}", property.Name, property.VTLPWSTR.Text);
                        property.VTLPWSTR.Text = "Updated " + DateTime.Now.ToString();
                        xl.Close();
                    }

    The intellisense for the Close method says it saves and closes the document and all parts, but the file is not updated.
    What am I missing here?

  • Never mind, I just need to call

    xl.CustomFilePropertiesPart.Properties.Save()

    before/instead of xl.Close()

Page 1 of 1 (2 items)