我正在制作一个 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();
}
}
}