获取excel表单中的数据
原贴链接:http://topic.csdn.net/t/20061119/14/5169103.html
先要添加 项目--引用--com--Microsoft excel 12.0 library对象库
path1=this.openFileDialog1.FileName;
//设置空值
object objMissing=System.Reflection.Missing.Value;
//打开excel文件
Excel.ApplicationClass my=new Excel.ApplicationClass();
my.Visible=true;
//打开工作簿
Excel.Workbook mybook=my.Workbooks.Open(path1.Trim(),objMissing,objMissing, objMissing,
objMissing, objMissing, objMissing,
objMissing, objMissing, objMissing,
objMissing, objMissing, objMissing);
Excel.Worksheet mysheet=(Excel.Worksheet)mybook.Worksheets.get_Item(1);
//分割字符串
string s,a,b;
a="";
b="";
s=((Excel.Range)mysheet.Cells[16,1]).Value.ToString();//读取数据
MessageBox.Show( "字符为 " + s);
先要添加 项目--引用--com--Microsoft excel 12.0 library对象库
path1=this.openFileDialog1.FileName;
//设置空值
object objMissing=System.Reflection.Missing.Value;
//打开excel文件
Excel.ApplicationClass my=new Excel.ApplicationClass();
my.Visible=true;
//打开工作簿
Excel.Workbook mybook=my.Workbooks.Open(path1.Trim(),objMissing,objMissing, objMissing,
objMissing, objMissing, objMissing,
objMissing, objMissing, objMissing,
objMissing, objMissing, objMissing);
Excel.Worksheet mysheet=(Excel.Worksheet)mybook.Worksheets.get_Item(1);
//分割字符串
string s,a,b;
a="";
b="";
s=((Excel.Range)mysheet.Cells[16,1]).Value.ToString();//读取数据
MessageBox.Show( "字符为 " + s);