我需要从电子表格中制作制表符分隔的文本文件:
https://s3.amazonaws.com/seller-templates/ff/na/us/Flat.File.Listingloader.xls
您会看到有两个标题:
我正在使用C#FileHelper库。我决定手动创建标题:
var engine = new FileHelperEngine<FlatFileListingsData>();
var orders = new List<FlatFileListingsData>();
orders.Add(new FlatFileListingsData() { ConditionType = "New", ConditionNote = "New", Price = 9, ProductId = "B009Q76ODU", ProductIdType = "ASIN", Quantity = 1, Sku = "Test1" });
string rowHeaders = "sku" + "\t" + "price" + "\t" + "quantity" + "\t" + "product-id" + "\t" + "product-id-type" + "\t" + "condition-type" + "\t" + "condition-note" + "\t" + "ASIN-hint" + "\t" + "title" + "\t" + "product-tax-code" + "\t" + "operation-type" + "\t" + "sale-price" + "\t" + "sale-start-date" + "\t" + "sale-end-date" + "\t" + "leadtime-to-ship" + "\t" + "launch-date" + "\t" + "is-giftwrap-available" + "\t" + "is-gift-message-available" + "\t" + "fulfillment-center-id" + "\t" + "main-offer-image" + "\t" + "offer-image1" + "\t" + "offer-image2" + "\t" + "offer-image3" + "\t" + "offer-image4" + "\t" + "offer-image5";
engine.HeaderText = "TemplateType=Offer" + "\t" + "Version=2014.0703" + Environment.NewLine + rowHeaders + Environment.NewLine + rowHeaders;
engine.WriteFile("output2.txt", orders);
[DelimitedRecord("\t")]
public class FlatFileListingsData
{
public string Sku { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
public string ProductId { get; set; }
public string ProductIdType { get; set; }
public string ConditionType { get; set; }
public string ConditionNote { get; set; }
}
这是我展示的xls文件的准确表示吗?有趣的是,我尝试将此文本文件上传到亚马逊。我收到有关缺少TemplateType = Offer行的错误:
文件的标题行缺失或无效。标题行仅供亚马逊使用,不得修改或删除。要更正此错误,请再次从卖家帮助中下载该模板并使用该新副本,或在现有文件的列标题正上方插入正确的标题行。
答案 0 :(得分:0)
我相信使用FileHelpers,您实际上可以设置所需的标题文本,以便插入它们时可以包含您选择的多行。您甚至可以使用BeforeWrite和AfterWrite事件(但不要混淆AfterWrite实际上是在处理之后但在写入流之前)。