Skip to content

Using the SaveAsByTemplate, configuration has no effect #810

Description

@The-Mojoo

Excel Type

  • XLSX
  • XLSM
  • CSV
  • OTHER

Upload Excel File

template.xlsx

MiniExcel Version

1.41.2

Description

Because I previously mentioned the issue of not supporting the long type being set as text,this.
So I changed my mind and went through the formatted template to upgrade to a file, but I found that the formatting set by miniexcel configuration did not work, including other configurations did not work, and I wanted to know what the problem was.

var tmplatePath = Path.Combine("C:\\Demo\\", $"template.xlsx");
var path = Path.Combine("C:\\Demo\\", $"{Guid.NewGuid()}.xlsx");

var data = new[]
{
    new
    {
        Num= 50.5, 
        BaiFen= 0.5, 
        LongText = "1550432695793487872",  
        DateField  = new DateTime(2025,6,17),
        TextField  = "ABC123"
    }
};

var config = new OpenXmlConfiguration
{
    AutoFilter = false,
    EnableAutoWidth=true,
    FastMode=true,
    DynamicColumns = new[]
    {
        new DynamicExcelColumn("Num")    { Format = "0.00"},
        new DynamicExcelColumn("BaiFen")    { Format = "0.00%"},
        new DynamicExcelColumn("DateField"){ Format = "yyyy-mm-dd"},
        new DynamicExcelColumn("TextField"){ Format = "@" }
    }
};

//MiniExcel.SaveAs(path, data , configuration: config);
MiniExcel.SaveAsByTemplate(path, tmplatePath, new { items = data }, configuration: config);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions