简体   繁体   English

FileHelpers选项卡定界两个标题

[英]FileHelpers Tab Delimited Two Headers

I need to make a tab delimited text file from a spreadsheet: 我需要用电子表格制作制表符分隔的文本文件:

https://s3.amazonaws.com/seller-templates/ff/na/us/Flat.File.Listingloader.xls https://s3.amazonaws.com/seller-templates/ff/na/us/Flat.File.Listingloader.xls

You will see that there are two headers: 您将看到有两个标题:

在此处输入图片说明

I am using the C# FileHelper library. 我正在使用C#FileHelper库。 I decided to create the headers manually: 我决定手动创建标题:

                            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; }
}

Is this an accurate representation of the xls file that I have shown? 这是我显示的xls文件的准确表示吗? Interestingly enough, I try upload this text file to Amazon. 有趣的是,我尝试将此文本文件上传到Amazon。 I receive an error about the TemplateType=Offer row being missing: 我收到有关缺少TemplateType = Offer行的错误:

The file's header row is missing or invalid. 文件的标题行丢失或无效。 The header row is for Amazon use only and must not be modified or deleted. 标题行仅供Amazon使用,不得修改或删除。 To correct this error, download the template again from seller Help and use that new copy, or insert the correct header row directly above the column headings in your existing file. 要更正此错误,请从卖方帮助中再次下载该模板并使用该新副本,或将正确的标题行直接插入现有文件中列标题的上方。

I believe that with FileHelpers you can actually set the header text you want so it can include multiple lines of your choosing by you inserting them. 我相信,实际上可以使用FileHelpers设置所需的标题文本,以便在插入时可以包含您选择的多行。 You can even use the BeforeWrite and AfterWrite events (but don't be confused AfterWrite is actually after processing but before written to stream). 您甚至可以使用BeforeWrite和AfterWrite事件(但请不要混淆,AfterWrite实际上是在处理之后但在写入流之前)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM