怎么样保存中文文字到.CVS文件
这是错误的,我想保存”年“”月“两个字到.csv,可是打开时却是乱码。各位前辈,这个该怎么解决呀
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _7__1csv文件保存
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCsv_Click(object sender, EventArgs e)
{
//Application.StartupPath 是相对路径
string Path = Application.StartupPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".csv";
WriteCSV(Path, 2016, 1213);
}
public void WriteCSV(string path, int Year, double Month)
{
if (!File.Exists(path))
{
FileStream fsWrite = new FileStream(path, FileMode.Create, FileAccess.Write);
StreamWriter SW = new StreamWriter(fsWrite);
StringBuilder SB = new StringBuilder();
SB.Append("年").Append(",").Append("月").Append(",");
SB.Append(s1).Append(",").Append(s2).Append(",");
SW.WriteLine(SB);
SW.Flush();
SW.Close();
fsWrite.Close();
}
StreamWriter SW1 = new StreamWriter(path, true, Encoding.Default);
StringBuilder SB1 = new StringBuilder();
SB1.Append(Year).Append(",").Append(Month).Append(",");
SW1.WriteLine(SB1);
SW1.Flush();
SW1.Close();
}
}
}