0

私は adz コレクターを作成しているので、ウェブサイトから広告を取得し、html を取得してタイトル、価格、説明を取得します。最後に DataTable に入力し続け、DataTable を CSV にエクスポートします。しかし、問題はテキストです。コードでは問題ありませんが、CSV にエクスポートすると次のようになります。

 · 75% of the Controller’s time will focus on accounting: Their role includes:  o 
 Bookkeeping  o Payroll  o Monthly HST  o Trust accounting; Ensuring compliance with the     Real 
 Estate Council requirements  o Financial Statement Preparation  · 25% Will be       management 
 functions:  o Supervise and assist with conveyancing  o Supervise all the office staff (4 - 
 6)  o Other day to day management functions.   Requirements and Qualifications  Essential 
 Skills   · Experience working with government regulated financial reporting  · Experience 
 working with large numbers of people in a customer service oriented role  ·     Experience with 
 Trust Accounting    Additional Assets ....

どこにでもシンボルがあります。エクスポートに使用するコードは次のとおりです。

public  void DataTable2CSV(DataTable table, string filename, string seperateChar)
    {

        StreamWriter sr = null;

        try
        {

            sr = new StreamWriter(filename, true);
            string seperator = "";
            StringBuilder builder = new StringBuilder();


                foreach (DataColumn col in table.Columns)
                {

                    builder.Append(seperator).Append(col.ColumnName);

                    seperator = seperateChar;
                }

                sr.WriteLine(builder.ToString());


            foreach (DataRow row in table.Rows)
            {

                seperator = "";
                builder = new StringBuilder();
                foreach (DataColumn col in table.Columns)
                {

                    builder.Append(seperator).Append(row[col.ColumnName]);
                    seperator = seperateChar;

                }

                sr.WriteLine(builder.ToString());

            }

        }

        finally
        {

            if (sr != null)
            {

                sr.Close();

            }

        }

    } 
4

2 に答える 2

2

テキストエンコーディングの混乱があります。つまり、CSV ファイルに書き込んでいるデータのエンコーディングが、CSV ビューア (Excel など) が期待するエンコーディングと一致しません。

詳細については、

文字エンコーディングと ’ 問題

特定の例では、これは UTF-8 を使用して読み取られた Unicode 文字 'RIGHT SINQLE QUOTATION MARK' (U+2019) ' の典型的な CP1252 表現です。UTF-8 では、その文字はバイト 0xE2、0x80、および 0x99 に存在します。CP1252 コードページ レイアウトを確認すると、これらのバイトが文字 â、€、および ™ を正確に表していることがわかります。

于 2013-02-12T05:03:46.430 に答える
0

最も可能性の高い理由は、システムと CSV がサポートできないフォントがあることです。エンコードのヘルプについては、この記事を確認してください。http://office.microsoft.com/en-us/help/choose-text-encoding-when-you-open-and-save-files-HA010121249.aspx

于 2013-02-12T05:05:49.847 に答える