FileHelpers 列 headers
FileHelpers columns headers
简单的问题,因为我在任何地方都找不到。如何为每一列设置自定义列名?我试着用这个:<FieldOrder(1), FieldTitle("Name")]>
但它说 FieldTitle
不存在。
它将只使用字段的名称。
[DelimitedRecord(",")]
class Product
{
// Must specify FieldOrder too
[FieldOrder(1)]
public string Name;
[FieldOrder(2)]
public string Description;
[FieldOrder(3)]
public string Size;
}
class Program
{
static void Main(string[] args)
{
var engine = new FileHelperEngine<Product>();
engine.HeaderText = engine.GetFileHeader();
var products = new Product[] { new Product() { Name = "Product", Description = "Some details", Size = "Large"} };
var productRecords = engine.WriteString(products);
Console.WriteLine(productRecords);
}
}
输出:
Name,Description,Size
Product,Some details,Large
如果你需要不同的东西,你可以这样做
engine.HeaderText = "whatever,whatever,whatever";
输出:
whatever,whatever,whatever
Product,Some details,Large
简单的问题,因为我在任何地方都找不到。如何为每一列设置自定义列名?我试着用这个:<FieldOrder(1), FieldTitle("Name")]>
但它说 FieldTitle
不存在。
它将只使用字段的名称。
[DelimitedRecord(",")]
class Product
{
// Must specify FieldOrder too
[FieldOrder(1)]
public string Name;
[FieldOrder(2)]
public string Description;
[FieldOrder(3)]
public string Size;
}
class Program
{
static void Main(string[] args)
{
var engine = new FileHelperEngine<Product>();
engine.HeaderText = engine.GetFileHeader();
var products = new Product[] { new Product() { Name = "Product", Description = "Some details", Size = "Large"} };
var productRecords = engine.WriteString(products);
Console.WriteLine(productRecords);
}
}
输出:
Name,Description,Size
Product,Some details,Large
如果你需要不同的东西,你可以这样做
engine.HeaderText = "whatever,whatever,whatever";
输出:
whatever,whatever,whatever
Product,Some details,Large