EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
279 stars 49 forks source link

CustomProperties throws an error #130

Closed PrzemyslawKlys closed 1 year ago

PrzemyslawKlys commented 1 year ago

As reported on Reddit: " One "Number" property was interpreted as VTDouble, although it's "68600". Added this handle and it works now."

internal WordCustomProperty(CustomDocumentProperty customDocumentProperty) {
    if (customDocumentProperty != null) {
        if (customDocumentProperty.VTInt32 != null) {
            this.Value = int.Parse(customDocumentProperty.VTInt32.Text);
            this.PropertyType = PropertyTypes.NumberInteger;
        } else if (customDocumentProperty.VTFileTime != null) {
            this.Value = DateTime.Parse(customDocumentProperty.VTFileTime.Text).ToUniversalTime();
            this.PropertyType = PropertyTypes.DateTime;
        } else if (customDocumentProperty.VTFloat != null) {
            this.Value = double.Parse(customDocumentProperty.VTFloat.Text);
            this.PropertyType = PropertyTypes.NumberDouble;
        } else if (customDocumentProperty.VTLPWSTR != null) {
            this.Value = customDocumentProperty.VTLPWSTR.Text;
            this.PropertyType = PropertyTypes.Text;
        } else if (customDocumentProperty.VTBool != null) {
            this.Value = bool.Parse(customDocumentProperty.VTBool.Text);
            this.PropertyType = PropertyTypes.YesNo;
        } else {
            throw new InvalidOperationException("Weird?");
        }
    }
}