发生乱码时:
string time = DateTime.Now.ToString("G");
string filePath = this.SavePath + "\\产能记录.csv";
string content = time + ","+ TodayNumber.ToString();
File.AppendAllText(filePath, "\r\n" + content);
写入后,表格乱码如下
**原因:**因csv以逗号分隔符换列,所以应该是编码问题导致解析逗号有问题,在方法中指定正确的编码格式即可,更改代码如下
string time = DateTime.Now.ToString("G");
string filePath = this.SavePath + "\\产能记录.csv";
string content = time + "," + TodayNumber.ToString();
File.AppendAllText(filePath, "\r\n" + content,Encoding.UTF8);
主要是在File.AppendAllText后指定UTF8的编码格式