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版本来定)
疯狂医院达什医生中文版(Crazy Hospital)
疯狂医院达什医生最新版是一款医院模拟经营类游戏,逼真的场景画
宝宝庄园官方版
宝宝庄园官方版是一款超级经典好玩的模拟经营类型的手游,这个游
桃源记官方正版
桃源记是一款休闲娱乐类的水墨手绘风格打造的模拟经营手游。玩家
长途巴士模拟器手机版
长途巴士模拟器汉化版是一款十分比真好玩的大巴车模拟驾驶运营类
房东模拟器最新版2024
房东模拟器中文版是一个超级有趣的模拟经营类型的手游,这个游戏