在Excel表格中传递值 [英] pass value in Excelsheet
问题描述
嗨...
i想使用asp.net传递excel中的值
i尝试下面的代码,但我想通过单元格没有和数据插入特定单元格我尝试下面的代码,但在这个代码中,我必须指定我需要的列和单元格否我在其中添加值,所以我的代码或任何其他代码中的任何修改,请告诉我。
hi...
i wan to pass value in excel using asp.net
i try below code but i want to pass cell no and data insert in perticular cell i try below code but in this code i must specifiy column in place i need and cell no in which i add value so any modification in my code or any other code to do this please tell me.
string szConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MySamplefile.xls;Extended Properties='Excel 8.0;HDR=No'";
OleDbConnection conn = new OleDbConnection(szConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand("INSERT INTO [sheet2$](columnName1,columnName2) VALUES ('A3','B3')", conn);
cmd.ExecuteNonQuery();
conn.Close();
- 代替列名columnName1,columnName2我想给任何单元格
谢谢
- in place of column name columnName1,columnName2 i want to give any Cell
thanks
推荐答案
(columnName1,columnName2)VALUES('A3','B3'),conn);
cmd.ExecuteNonQuery();
conn.Close();
(columnName1,columnName2) VALUES ('A3','B3')", conn); cmd.ExecuteNonQuery(); conn.Close();
- 到位列名columnName1,columnName2我想给任何单元格
谢谢
- in place of column name columnName1,columnName2 i want to give any Cell
thanks
使用OLEDB [ ^ ]用于表格,数组。
如果要在特定单元格中添加一些值,例如:A1,C5, E9,你需要:
1)创建Excel实例,
''后期绑定
Inserting data into Excel Sheet with OLEDB[^] is provided for tables, arrays.
If you want to add some values into particular cells, for example: A1, C5, E9, you need to:
1) Create instance of Excel,
''late binding
xlApp = CreateObject("Excel.Application")
2)打开工作簿,
2) Open workbook,
xlWbk = xlApp.Workbooks.Open("FullFileName")
3)将数据添加到特定单元格:
3) Add data into particular cells:
xlWsh = xlWbk.Worksheets("Sheet1")
xlWsh.Range("A1") = "String Value"
xlWsh.Range("C5") = 2005 'numeric value
xlWsh.Range("E9") = "Client No. 203584"
以上代码是VB.NET。 C#中的示例:
http://www.c-sharpcorner.com/uploadfile/ae35ca/read-and-write-excel-data-using-C-Sharp/ [ ^ ]
http://csharp.net-informations.com/excel/csharp-excel-tutorial。 htm [ ^ ] CP / KB
:
使用C#将数据写入Excel [ [
Excel Reader [<小时ef =http://www.codeproject.com/Articles/16210/Excel-Readertarget =_ blanktitle =New Window> ^ ]
Above code is in VB.NET. Examples in C#:
http://www.c-sharpcorner.com/uploadfile/ae35ca/read-and-write-excel-data-using-C-Sharp/[^]
http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm[^]
on CP KB:
Write Data to Excel using C#[^]
Excel Reader[^]
这篇关于在Excel表格中传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!