C# 写Excel表 单元格操作
我的程序大致意思为string cell[5] = {"B","C","D","E","F"};
For( i=1;i<=40;i++)
For(j=1;j<=5;j++)
{cellname= cell[j]+string.format("%d",i+1);
string data = "22.5";
Excel.Write("sheet1",cellname,(i+1),data);}
Excel操作函数为:
write(string sheetname, string cellname, int lines, string writedata)
{
OleDbCommand command= null;
if(this,conOleDB != null)
{
try
{
this.conOleDB.Open();
command = new OleDbCommand(string.Format("UPDATE [{0}${1}:{2}] Set F{3}=\"{4}\"", new object[] { sheetName, cell Name, cellName, Lines, value2Write }), this.conOleDB);
command.ExecuteNonQuery();
}
catch(Exception exception)
{
.......
}
}
如果想实现在Excel表指定区域(2-42行,(B-F)列写入数据,应该如何更改)??
这段代码可以写入数据,但是每次都只能在第一行写(B-F)单元格,坐等高手指点