問題は、エクスポート自体ではなく、フィールドをカンマで区切る方法と、フィールドにカンマがあることです。文字列にコンマが含まれる最後のフィールドに到達するまで、すべて正常に機能し、区切ります
私のコード:
foreach (var item in jobSortedReportData)
{
sb.Append("\"").Append(item.Title).Append("\",\"").Append(item.Total).Append("\",\"").Append(item.Week6).Append("\",\"").Append(item.Week5).Append("\",\"").Append(item.Week4).Append("\",\"").Append(item.Week3).Append("\",\"").Append(item.Week2).Append("\",").Append(item.Week1).Append(Environment.NewLine);
}
byte[] textBytes2 = Encoding.UTF8.GetBytes(sb.ToString());
これが生成する出力:
Number 1 Job Search 0 **Bathroom Fitter, Plumbing: 100** Carpenter, Joinery: 99 Carpenter, Joinery: 81 Carpenter, Joinery: 209 Electrician, Domestic Electrical: 495 **Bathroom Fitter Plumbing: 112**
Number 2 Job Search 0 Carpenter, Joinery: 97 Bathroom Fitter, Plumbing: 99 Bathroom Fitter, Plumbing: 79 Bathroom Fitter, Plumbing: 150 Bathroom Fitter, Plumbing: 453 Builder Window Installation: 75
Number 3 Job Search 0 Builder, Window Installation: 85 Building Contractor, Kitchen Fitting: 97 Plumber, Bathroom Fitting: 51 Builder, Window Installation: 134 Heating Engineer, Gas Installation: 451 Bathroom Fitter Bathroom Fitting: 74
生のビュー:
"Number 3 Job Search","0","Builder, Window Installation: 85","Building Contractor, Kitchen Fitting: 97","Plumber, Bathroom Fitting: 51","Builder, Window Installation: 134","Heating Engineer, Gas Installation: 451",Bathroom Fitter, Bathroom Fitting: 74
"Number 1 Tradesmen Search","0","Painter & Decorator: 316","Painter & Decorator: 229","Painter & Decorator: 146","Builder: 324","TV Aerials & In-home Entertainment Installer: 1378",Electrician: 247
"Number 2 Tradesmen Search","0","Builder: 171","Builder: 191","Plumber: 114","Plumber: 295","Builder: 551",Builder: 205
"Number 3 Tradesmen Search","0","Plumber: 123","Plumber: 160","Builder: 108","Painter & Decorator: 231","Domestic Electrical: 495",Painter & Decorator: 160
上記で"Bathroom Fitter, Plumbing: 100"
は、3 番目の列に a,
が含まれていますが、文字列全体が 1 つの Excel フィールドに保持されます。最後の列になると、 FitterとPlumbingの間の文字列に"Bathroom Fitter Plumbing: 112"
a があるため、今何が起こっているのか this はセパレーターと見なされるため、Excel ではこれを 2 つのセルに分割するため、 1つのセルと次。文字列全体が 1 つのセルにある必要があります。これは最後の列でのみ行われますか?? これを修正するのを手伝ってください。,
Bathroom Fitter
Plumbing:112
ありがとう