vb.net excel

xiaolong24 2009-09-15 04:31:27
用vb.net 如何导出数据库里的数据到一excel文件中
...全文
86 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qzr820 2009-09-24
  • 打赏
  • 举报
回复
项目----添加引用---com选项卡-----Microsoft Excel 11.0 Object Library
seleucids 2009-09-24
  • 打赏
  • 举报
回复
为什么我这里显示 未定义类型Excel.Application
aliuying 2009-09-23
  • 打赏
  • 举报
回复
我有个比较简洁自己使用的代码,要的话把邮件给我
APP开发王 2009-09-15
  • 打赏
  • 举报
回复
For i As Integer = 0 To products.Length - 1

Dim product As String = products(i)
sheet = DirectCast(wbook1.Worksheets.Item(i + 1), Excel.Worksheet)
sheet.Name = product
Dim tb As DataTable = dbtool.getProductInfo(_vendor, product)
disply("ganerate data product: " & product & " ........")

sheet.Cells(5, 2) = dbtool.getVendorNameByvendorID(_vendor)
sheet.Cells(7, 2) = product
If tb IsNot Nothing And tb.Rows.Count > 0 Then
rowCount = tb.Rows.Count
disply("Rows count: " & rowCount)

'-------------Auto Fill the formart for the columns-------------------------
Dim oldRange As Excel.Range = sheet.Range("A" & (BlankRow + 1).ToString & ":AG" & (BlankRow + 1).ToString, missing)
Dim desRange As Excel.Range = sheet.Range("A" & (BlankRow + 1) & ":AG" & (rowCount + BlankRow + 1).ToString, missing)
sheet.Activate()
oldRange.Select()
oldRange.AutoFill(desRange, Excel.XlAutoFillType.xlFillDefault)
'-------------Auto Fill the formart for the columns-------------------------
For r As Integer = 0 To tb.Rows.Count - 1

sheet.Cells(r + 1 + BlankRow, 1) = tb.Rows(r)("TELCO_ID")
sheet.Cells(r + 1 + BlankRow, 2) = tb.Rows(r)("CUST_NAME")
sheet.Cells(r + 1 + BlankRow, 3) = tb.Rows(r)("SVC_NO")
sheet.Cells(r + 1 + BlankRow, 4) = tb.Rows(r)("SUB_PDT")
sheet.Cells(r + 1 + BlankRow, 5) = tb.Rows(r)("CURR")
sheet.Cells(r + 1 + BlankRow, 6) = tb.Rows(r)("TP_MRC_INC_TAX")
APP开发王 2009-09-15
  • 打赏
  • 举报
回复
Dim missing As Missing = System.Reflection.Missing.Value
Dim excelApp As New Excel.ApplicationClass()
excelApp.Visible = False
Dim wbook1 As Excel.Workbook = Nothing
Dim sheet As Excel.Worksheet = Nothing

Try
disply("loading Excel tamplate......")

For Each _vendor As String In VendorIDs

wbook1 = excelApp.Workbooks.Open(Excel_PaymentFile_template, missing, missing, missing, missing, missing, _
missing, missing, missing, missing, missing, missing, _
missing, missing, missing)
wbook1.Unprotect(excel_templateFile_Password)
sheet = DirectCast(wbook1.Worksheets.Item(1), Excel.Worksheet)
Dim rowCount As Integer = 8
disply("get Data from DB......")
Dim strshort As String = dbtool.getVendorShortName(_vendor)

If strshort Is Nothing Then

'close without change template file
wbook1.Close(False, missing, missing)
excelApp.Quit()
GC.Collect()
disply("Cn not find any company info by this vendor: " & _vendor, Color.Red)
Exit Sub
End If
.
..
骑猪看海 2009-09-15
  • 打赏
  • 举报
回复
用数据源控件啊
水猿兵团五哥 2009-09-15
  • 打赏
  • 举报
回复

Dim xlsApp As Excel.Application
Dim xlsBook As Excel.Workbook
Dim xlsSheet As Excel.Worksheet

xlsApp = CreateObject("Excel.Application")
xlsBook = xlsApp.Workbooks.Add
xlsApp.Application.Visible = True

xlsSheet = xlsBook.Worksheets(1)

With xlsSheet
.Activate()
.Range("A1").Select()
.Paste()
.Cells.Select()
.Cells.EntireColumn.AutoFit()
.Range("A1").Select()
End With

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧