c#读取Excel 提取在Excel中使用到的Excel函数
2个回答
展开全部
用查询表的方式查询并show在数据集控件上。
代码publicstaticstring strCon =" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =C:\\08.xls;Extended Properties=Excel 8.0";
publicstatic DataSet ds;
protectedvoid Page_Load(object sender, EventArgs e)
{
OleDbConnection conn =new OleDbConnection(strCon);
string sql ="select * from [Sheet1$]";
conn.Open();
OleDbDataAdapter myCommand =new OleDbDataAdapter(sql, strCon);
ds =new DataSet();
myCommand.Fill(ds, "[Sheet1$]");
conn.Close();
datagrid1.DataMember ="[Sheet1$]";
datagrid1.DataSource = ds;
datagrid1.DataBind();
//Excel.Application excel = new Excel.Application();
//excel.Application.Workbooks.Add(true);
//excel.Visible = true;
}
一个一个单元格的进行插入
代码 1string str =@"Data Source=IT-428E4EA4B0C7\SQLEXPRESS;Initial Catalog=TestBase;Integrated Security=True";
2 SqlConnection conn =new SqlConnection(str);
3 conn.Open();
4int n =0;
5for (int i =1; i <20; i++)
6 {
7if (n >3)
8break;
9else
10if (msheet.Cells.get_Range("A"+ i, Type.Missing).Text.ToString() ==""&& n <=3)
11 { n++; }
12else
13 {
14 //循环获取excel单元格的值一次一次的插入,excuteSql为执行的存储过程
15 excuteSql(msheet.Cells.get_Range("B"+ i, Type.Missing).Text.ToString(),
16 msheet.Cells.get_Range("B"+ (i +1), Type.Missing).Text.ToString(),
17 msheet.Cells.get_Range("B"+ (i +2), Type.Missing).Text.ToString(),
18 conn);
19 i = i +3;
20
21 }
22 }
23
24 conn.Close();
代码publicstaticstring strCon =" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =C:\\08.xls;Extended Properties=Excel 8.0";
publicstatic DataSet ds;
protectedvoid Page_Load(object sender, EventArgs e)
{
OleDbConnection conn =new OleDbConnection(strCon);
string sql ="select * from [Sheet1$]";
conn.Open();
OleDbDataAdapter myCommand =new OleDbDataAdapter(sql, strCon);
ds =new DataSet();
myCommand.Fill(ds, "[Sheet1$]");
conn.Close();
datagrid1.DataMember ="[Sheet1$]";
datagrid1.DataSource = ds;
datagrid1.DataBind();
//Excel.Application excel = new Excel.Application();
//excel.Application.Workbooks.Add(true);
//excel.Visible = true;
}
一个一个单元格的进行插入
代码 1string str =@"Data Source=IT-428E4EA4B0C7\SQLEXPRESS;Initial Catalog=TestBase;Integrated Security=True";
2 SqlConnection conn =new SqlConnection(str);
3 conn.Open();
4int n =0;
5for (int i =1; i <20; i++)
6 {
7if (n >3)
8break;
9else
10if (msheet.Cells.get_Range("A"+ i, Type.Missing).Text.ToString() ==""&& n <=3)
11 { n++; }
12else
13 {
14 //循环获取excel单元格的值一次一次的插入,excuteSql为执行的存储过程
15 excuteSql(msheet.Cells.get_Range("B"+ i, Type.Missing).Text.ToString(),
16 msheet.Cells.get_Range("B"+ (i +1), Type.Missing).Text.ToString(),
17 msheet.Cells.get_Range("B"+ (i +2), Type.Missing).Text.ToString(),
18 conn);
19 i = i +3;
20
21 }
22 }
23
24 conn.Close();
追问
谢谢~
我想把一个单元格内 用到的 所有函数 提取出来
有没有什么判断的属性 什么提取的属性什么的呀? 怎么能提取用到的函数名称呢?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询