以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- sql所有表数据如何批量导出为excel (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=180856) |
-- 作者:chen_sheng -- 发布时间:2022/10/18 15:32:00 -- sql所有表数据如何批量导出为excel 前一阵经历了勒索病毒 想每天把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() |
-- 作者:有点蓝 -- 发布时间:2022/10/18 15:41:00 -- 遍历获取列名:http://www.foxtable.com/webhelp/topics/1428.htm 比如 For c As Integer = 0 To DataTables("订单").DataCols.Count -1 Sheet(0, c).Value = DataTables("订单").DataCols(c).name Next 防毒我也不懂。备份数据库的话,SqlServer可以设置计划自动备份。但是建议备份后,下载到多个地方保存,比如本地,然后在复制一份到移动硬盘里。
|
-- 作者:chen_sheng -- 发布时间: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")
|
-- 作者:有点蓝 -- 发布时间:2022/10/18 15:58:00 -- Sheet(r +1, c).Value = dt.DataRows(r)(dt.DataCols(c).name) |