2

クラスをCSVにエクスポートするための多くの解決策を見つけましたが、私の問題は次のとおりです。

エクスポートしようとしているクラスには、observablecollection であるプロパティがあります。例えば:

public class ShipmentForExport
    {
        public string WaybillNumber { get; set; }
        public DateTime WaybillDate { get; set; }
        public string CustomerName { get; set; }
        public string CustomerCode { get; set; }
        public string CollectingBranchName { get; set; }
        public string CollectingBranchCode { get; set; }
        public string RecipientName { get; set; }
        public string RecipientPhoneNumber { get; set; }
        public string RecipientCellphoneNumber { get; set; }
        public string RecipientCompany { get; set; }
        public string DestinationAddress1 { get; set; }
        public string DestinationAddress2 { get; set; }
        public string DestinationCity { get; set; }
        public string DestinationSuburb { get; set; }
        public string DestinationProvince { get; set; }
        public string DestinationCountry { get; set; }
        public string DestinationPostalCode { get; set; }

        ***public ObservableCollection<InHouseParcel> Parcels { get; set; }***

    }

出荷のリストをcsvにエクスポートしようとすると機能しますが、明らかに小包は希望どおりにエクスポートされません。

Filehelpers Library と csvHelper も使用してみました。

どんな助けでも大歓迎です!!

4

2 に答える 2

0

CsvHelper (私が管理しているライブラリ) を使用しています...

コレクション プロパティの書き込みはサポートされていないため、書き込む場合は手動で書き込む必要があります。

foreach( var record in records )
{
    csv.WriteField( record.WaybillNumber );
    ...
    foreach( var parcel in record.Parcels )
    {
        csv.WriteField( parcel );
    }
}

マッピングに追加できるため、読み取りが少し簡単になります。

Map( m => m.Parcels ).ConvertUsing( row =>
{
    var oc = new ObservableCollection<InHouseParcel>();
    var parcel = row.GetField<InHouseParcel>( 17 );
    oc.Add( parcel );
} );

フィールド値をに変換InHouseParcelし、行の残りのフィールドをループする必要があります。その仕事はあなたに任せます。

于 2014-04-10T21:28:34.420 に答える