I am making a adz collector, so i get the ad from a website and i take the html get the title,price,description.And keep inputting into a DataTable at the end export the DataTable to CSV.But the issue is the text is fine in the code but when its exported to CSV its like :
· 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 ....
There are symboles everywhere , the code i use to export is below:
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();
}
}
}
You have text encoding confusion. In other words, the encoding of the data you are writing to the CSV file does not match the encoding expected by the CSV viewer (e.g. Excel).
For more detail see
Character Encoding and the ’ Issue