Reputation: 2653
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();
}
}
}
Upvotes: 0
Views: 1150
Reputation: 1647
The most probably reason could be that there's a font your system and CSV is unable to support. Check this article for encoding help. http://office.microsoft.com/en-us/help/choose-text-encoding-when-you-open-and-save-files-HA010121249.aspx
Upvotes: 0
Reputation: 150208
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
In the particular ’ example, this is a typical CP1252 representation of the Unicode Character 'RIGHT SINQLE QUOTATION MARK' (U+2019) ’ which was been read using UTF-8. In UTF-8, that character exist of the bytes 0xE2, 0x80 and 0x99. If you check the CP1252 codepage layout, then you'll see that those bytes represent exactly the characters â, € and ™.
Upvotes: 2