您的位置:程序门 -> .net技术 -> vb.net



vb.net获得excel的sheet1的名称


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb.net获得excel的sheet1的名称
发表于:2008-03-14 14:55:30 楼主
我查了查,发现有的文章引用了 excel.application  可是我在 vb.net中 创建不了 excel.application,不知道为什么

sqlcmd.commandtext = "select * into  " & tname & " from openrowset('microsoft.jet.oledb.4.0','excel 8.0;database=" & fname & "' , 'select * from [fsdf$]')"

我想在上面的代码中 fsdf$ 使用动态的变量 ,怎么才能动态的获得excel的 sheet 名称呢?
发表于:2008-03-14 15:31:541楼 得分:0
在【项目】中要【添加引用】,选择com 找到microsoft excel 11.0 object library 就可以了。
dim xlapp as excel.application
dim xlbook as excel.workbook
dim xlsheet as excel.worksheet
xlapp = new excel.application
xlbook = xlapp.workbooks.open("excel文件路径")
xlsheet = xlbook.worksheets(1)
  msgbox xlsheet.name
  xlsheet = nothing
xlbook.close(false)
xlbook = nothing
xlapp.quit()
xlapp = nothing
发表于:2008-03-15 14:28:002楼 得分:0
vb.net code
'获取数据表列表 dim table_list as data.datatable = getschematable(dbfconn, "table") me.cb_table_list.datasource = table_list.defaultview me.cb_table_list.valuemember = "table_name" me.cb_table_list.displaymember = "table_name" private function getschematable(byval connection as data.oledb.oledbconnection, byval type as string) ' 获取数据表列表 'type 有:"table,view,access table,system table", type = type.toupper connection.open() dim table_list as data.datatable table_list = connection.getoledbschematable(data.oledb.oledbschemaguid.tables, new object() {nothing, nothing, nothing, type}) connection.close() return table_list end function
发表于:2008-03-17 14:05:013楼 得分:0
第一种方法好用,速度好像有点慢
第二种方法看不太懂啊,哪位高手能讲讲
发表于:2008-03-17 22:06:154楼 得分:0
vb.net code
'获取数据表列表 dim table_list as data.datatable = getschematable(dbfconn, "table") me.cb_table_list.datasource = table_list.defaultview me.cb_table_list.valuemember = "table_name" me.cb_table_list.displaymember = "table_name"


这段代码是将excel表名填充到一个下拉列表框中


快速检索

最新资讯
热门点击