admin管理员组文章数量:1583033
1. 包含库
(1)在项目中添加Microsoft.Office.Interop.Excel的程序包。
(2)包含库:using Microsoft.Office.Interop.Excel;
(3)为使用方便和避免混淆:using Excel = Microsoft.Office.Interop.Excel;
2. 创建保存文件和文件头
string filePath = "D:\\Project\\SaveData";
string data = DateTime.Now.ToString("yyyy-MM-dd");
if (!Directory.Exists(filePath + "\\" + data))
{
Directory.CreateDirectory(filePath + "\\" + data);
}
string time = DateTime.Now.ToString("HH_mm_ss");
mFullPath = filePath + "\\" + data + "\\" + time + ".csv";
FileStream fs = File.Create(mFullPath);
fs.Close();
using (StreamWriter writer = File.CreateText(mFullPath))
{
writer.WriteLine("WaferID,PreTHK,PostTHK");
writer.Close();
}
3. 在需要的时候向文件写数据
//保存数据
using (StreamWriter writer = File.AppendText(mFullPath))
{
writer.WriteLine("{0},{1},{2}", TxtBoxWaferID.Text, TxtBoxPre.Text, TxtBoxPost.Text);
writer.Close();
}
4. 生成表格
本文标签: 数据officeMicrosoftExcelInterop
版权声明:本文标题:C#中利用Microsoft.Office.Interop.Excel向Excel中写数据 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1727907642a1137569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论