EPPlusSoftware / EPPlus

EPPlus-Excel spreadsheets for .NET
https://epplussoftware.com
Other
1.82k stars 277 forks source link

PivotTable sometimes can not get Field Name property #1683

Open yangmijun opened 2 days ago

yangmijun commented 2 days ago

EPPlus usage

Noncommercial use

Environment

Windows 10

Epplus version

7.4.2

Spreadsheet application

Excel

Description

Use EPPlus to open existing xlsx file, then create pivot table. then output all the field name in the pivottable, sometimes the field name will output "OfficeOpenXml.Style.ExcelRichTextCollection". The .xlsx file is edited by Excel, and I added some title style, and some title has Chinese charecter. This issue will stop me from getting some pivotfield by name.

yangmijun commented 2 days ago

HelloWorld.xlsx This is sample file

yangmijun commented 2 days ago

`static void Main(string[] args) { ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using (var package = new ExcelPackage("HelloWorld.xlsx")) { var dataSheet = package.Workbook.Worksheets["Data"]; var pivotSheet = package.Workbook.Worksheets["Pivot"];

    //create pivot table
    var pivotDataRange = dataSheet.Cells[4, 2, 14, 8];
    var pivotTable = pivotSheet.PivotTables.Add(pivotSheet.Cells["C3"], pivotDataRange, "TestPivotTable");

    foreach (var field in pivotTable.Fields)
    {
        if (field != null)
        {
            Console.WriteLine(field.Name);
        }
    }

    package.Save();
}

}` This is sample code.

yangmijun commented 2 days ago

The output would be: OfficeOpenXml.Style.ExcelRichTextCollection OfficeOpenXml.Style.ExcelRichTextCollection TimelEng 时间 Number String 字符串