最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
vb.net 数据导入excel代码
时间:2010-07-20 编辑:简简单单 来源:一聚教程网
vb.net 数据导入excel代码
这是一款简单的由vb.net把数据库教程的数据导入到execel实例哦,如果你正在找相关的.net把数据导入到数据表的话,这是一款完整的可用代码。
imports system.data
imports system.data.sqlclient
public class form1
dim app as new excel.application
dim exbook as excel.workbook
dim exsheet as excel.worksheet
dim exrange as excel.range
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
exbook = app.workbooks.open("d:www.111com.netc.xls")
exsheet = exbook.sheets(1)
dim myconnection as new sqlconnection("data source=192.168.0.1;initial catalog=test;user id=sa;password=abc")
dim mycommand as sqlcommand = new sqlcommand()
myconnection.open()
mycommand.connection = myconnection
mycommand.commandtext = "select un001,un002,un003 from bcun"
mycommand.commandtype = commandtype.text
dim myreader as sqldatareader = mycommand.executereader
dim i as integer = 1
do while myreader.read()
exsheet.cells(i, 1) = myreader.getstring(0)
exsheet.cells(i, 2) = myreader.getstring(1)
exsheet.cells(i, 3) = myreader.getstring(2)
i = i + 1
loop
myreader.close()
myconnection.close()
exbook.save()
exbook.close()
app.workbooks.close()
app.quit()
mycommand.connection.close()
end sub
end class
/*
请注意在引用中添加com组件:microsoft excel 11.0 object library(不一定是11.0的,由你用的excel版本来定)
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10