C#怎么在一个已经存在的EXCEL里写入数据
展开全部
添加excel类库引用
//加载excel
Application app = new Application();
Workbooks wb = app.Workbooks;
_Workbook _wb = wb.Add("excel路径");
//获取sheet
Sheets sh = _wb.Sheets;
_Worksheet _wsh = (_Worksheet)sh.get_Item(1);
_wsh.Cells[3, 2] = person.Name;//3为excel行,2为excel列
_wsh.SaveAs("填写完成后要保存的路径",
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
_wb.Close();
wb.Close();
//加载excel
Application app = new Application();
Workbooks wb = app.Workbooks;
_Workbook _wb = wb.Add("excel路径");
//获取sheet
Sheets sh = _wb.Sheets;
_Worksheet _wsh = (_Worksheet)sh.get_Item(1);
_wsh.Cells[3, 2] = person.Name;//3为excel行,2为excel列
_wsh.SaveAs("填写完成后要保存的路径",
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
_wb.Close();
wb.Close();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询