Foxtable(狐表)用户栏目专家坐堂 → sql所有表数据如何批量导出为excel


  共有6694人关注过本帖树形打印复制链接

主题:sql所有表数据如何批量导出为excel

帅哥哟,离线,有人找我吗?
chen_sheng
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:700 积分:6230 威望:0 精华:0 注册:2018/5/10 9:05:00
sql所有表数据如何批量导出为excel  发帖心情 Post By:2022/10/18 15:32:00 [显示全部帖子]

前一阵经历了勒索病毒  想每天把sql数据导出为excel 并发送到邮箱,防止中毒后可以快速恢复数据

1。邮件发送已经借助帮助可以实现
2。如下帮助代码想按照sql数据库结构直接导出,不想填写指定表头。
3.  官方是否有防毒备份数据更加好的办法可以指导,谢谢!

Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "S elect  * From {物料档案} "
Dim dt As  DataTable  = cmd.ExecuteReader()
Dim nms() As String = {"产品编号","分类","规格","备注"}
Dim Book As New XLS.Book
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim Style As Xls.Style = Book.NewStyle
Style.BackColor = Color.Red
For c As Integer = 0 To nms.Count -1
    Sheet(0, c).Value = nms(c)
Next
For r As Integer = 0 To dt.DataRows.Count - 1
    For c As Integer = 0 To nms.Count -1
        Sheet(r +1, c).Value = dt.DataRows(r)(nms(c))
    Next
Next
'打开工作簿
Book.Save("d:\test.xls")
Dim Proc As New Process
Proc.File = "d:\test.xls"
Proc.Start()

 回到顶部
帅哥哟,离线,有人找我吗?
chen_sheng
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:700 积分:6230 威望:0 精华:0 注册:2018/5/10 9:05:00
  发帖心情 Post By:2022/10/18 15:56:00 [显示全部帖子]

Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "S elect  * From {物料档案} "
Dim dt As  DataTable  = cmd.ExecuteReader()
Dim nms() As String = {"产品编号","分类","规格","备注"}
Dim Book As New XLS.Book
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim Style As Xls.Style = Book.NewStyle
Style.BackColor = Color.Red
For c As Integer = 0 To nms.Count -1
    Sheet(0, c).Value = nms(c)
Next
For c As Integer = 0 To dt.DataCols.Count -1
    Sheet(0, c).Value = dt.DataCols(c).name
Next
For r As Integer = 0 To dt.DataRows.Count - 1
    For c As Integer = 0 To dt.DataCols.Count -1
        Sheet(r +1, c).Value = dt.DataRows(r)(nms(c))     '帮忙指导一下这里该如何改,谢谢!
    Next
Next
Book.Save("d:\test.xls")

 回到顶部