C# 通过文件帮助程序将标题行添加到Excel文件

C# 通过文件帮助程序将标题行添加到Excel文件,c#,.net,filehelpers,C#,.net,Filehelpers,我正在跟踪,但我不知道如何在最终输出的excel文件中创建标题行。您必须提供一个只包含标题的“模板”excel文件 // Class record [DelimitedRecord("|")] public class MyClass { public string Field1 { get; set; } public int Field2 { get; set; } public string Field3 { get; set; } } class Program

我正在跟踪,但我不知道如何在最终输出的excel文件中创建标题行。

您必须提供一个只包含标题的“模板”excel文件

// Class record
[DelimitedRecord("|")]
public class MyClass
{
    public string Field1 { get; set; }
    public int Field2 { get; set; }
    public string Field3 { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        // create some data to export
        MyClass[] rows = new MyClass[2] { 
          new MyClass() { Field1 = "Apples",  Field2 = 23, Field3 = "Yes" },
          new MyClass() { Field1 = "Oranges", Field2 = 17, Field3 = "No"} 
        };

        ExcelStorage provider = new ExcelStorage(typeof(MyClass));
        // Set the destination Excel spreadsheet
        provider.FileName = @"MyClass.xlsx";

        // Template.xlsx contains just the column headers on row 1
        provider.TemplateFile = @"Template.xlsx"; 
        // StartRow is after the header row
        provider.StartRow = 2; 

        provider.OverrideFile = true;
        provider.InsertRecords(rows);
    }
}

你的链接是指向主FileHelpers页面的。所以我必须有另一个excel文件,其中只有标题?它不能根据字段计算出来?没错。
ExcelStorage.InsertRecords()
的当前(2.9.9)实现不会生成任何头。