Skip to content

Properties on Worksheet.PrinterSettings returns double.NaN #2151

@swmal

Description

@swmal

Whilst not a bug per se, this can cause problems for someone doing this:

double? bottomMargin = default;
ws.PrinterSettings.BottomMargin = bottomMargin ?? ws.PrinterSettings.BottomMargin;

Since bottomMargin has no value the return value from ws.PrinterSettings.BottomMargin will be assigned to itself, which probably makes sense. However since the getter of these properties reads directly from the xml via the GetXmlNodeDouble method they will return double.NaN if there is no value set. And this causes "NaN" to be written to the xml and causes a corrupt workbook.

Possible improvements

  1. Improve the xml documents for the properties in the PrinterSettings class and add the information that they return NaN if there is no value set.
  2. We could perhaps ignore NaN values in the setters - if the current value is Null and the new value is double.NaN don't write the new value to the xml.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions