日期:2014-05-17  浏览次数:21013 次

Excel表操作
如何将Excel表中的某单元格的值赋给另外一个。比如此某列值为空,把该行的某个单元格的值赋给这个空单元格。

------解决方案--------------------
C# code
修改第一行Name的值为张三
string strComm = "update [Sheet1$] set Name='张三' where id = 1";
OleDbConnection myConn = new OleDbConnection(strConn);
myConn.Open();
OleDbCommand com = new OleDbCommand(strComm, myConn);
com.ExecuteNonQuery();
myConn.Close();

------解决方案--------------------
C# code
  MSEXCEL.Application excelapp=new Microsoft.Office.Interop.Excel.Application();
                object objOpt = System.Reflection.Missing.Value;
                MSEXCEL.Workbook exceelDoc = excelapp.Workbooks.Open(this.saveFileDialog1.FileName, objOpt, false, objOpt, objOpt, objOpt, true, objOpt, objOpt, true, objOpt, objOpt, objOpt, objOpt, objOpt);
                MSEXCEL.Worksheet ws = (MSEXCEL.Worksheet)exceelDoc.Sheets[1];
                MSEXCEL.Range r;
                r = ws.get_Range("I12", "I12");//获得I12,I12单元格
                  r.Value2=赋值;(想取的单元格的Value2)