dotnet / Open-XML-SDK

Open XML SDK by Microsoft
https://www.nuget.org/packages/DocumentFormat.OpenXml/
MIT License
4.03k stars 547 forks source link

FontName becomes OpenXmlUnknownElement #1792

Open andrewtsybulia opened 1 month ago

andrewtsybulia commented 1 month ago

Hi team Describe the bug After updating to version 3.1.0, I've encountered a bug. When I create a DocumentFormat.OpenXml.Spreadsheet.RunProperties with FontName as a child element, it changes the FontName to OpenXmlUnknownElement.

Screenshots image

To Reproduce

using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using Xunit;

namespace SOME_NAME_SPACE;

public class ExcelConvertingHelperTests
{
    [Fact]
    public void BuildFont_Should_Return_RunProperties_With_FontName()
    {
        // Arrange
        var runProps = new RunProperties(new FontName());
        var spreadsheetDocument = SpreadsheetDocument.Create($"SampleWithRunProperties.xlsx", SpreadsheetDocumentType.Workbook);
        var workbookPart = spreadsheetDocument.AddWorkbookPart();
        var worksheetPart = workbookPart.AddNewPart<WorksheetPart>();
        worksheetPart.Worksheet = new Worksheet(new SheetData(new Row(new Cell(new InlineString(new Run(runProps))))));
        workbookPart.Workbook = new Workbook(new Sheets(new Sheet()));
        spreadsheetDocument.Save();

        // Act
        var result = worksheetPart.Worksheet.Descendants<RunProperties>().First().FirstChild;

        // Assert
        Assert.True(result is FontName);
        Assert.True(result is not OpenXmlUnknownElement);

        spreadsheetDocument.Dispose();
    }
}
  1. Run the test
  2. See error

Expected behavior FontName becomes OpenXmlUnknownElement, I expect it to stay FontName.

Desktop (please complete the following information):

rettoua commented 2 days ago

any thoughts on that ? @twsouthwick