Foxtable(狐表)用户栏目专家坐堂 → [求助]EXCEL文件中怎么复制一个工作表


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

主题:[求助]EXCEL文件中怎么复制一个工作表

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


加好友 发短信
等级:超级版主 帖子:110738 积分:563610 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2024/9/11 12:29:00 [显示全部帖子]


如果不考虑合并单元格,这种方法也可以,原理就是添加一个sheet,然后把之前的sheet的内容全部复制到新的sheet里
Dim Products As List(Of String)
Products = DataTables("出库").SQLGetValues("出库用途")
Dim Book As New XLS.Book(ProjectPath & "Attachments\出库单.xls") '打开模板
Dim fl As String = ProjectPath & "Reports\出库单.xls"
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim Sheet2 As XLS.Sheet
If Products.Count > 0 Then Sheet(1,7).Value = "<出库用途 ='" & Products(0) & "'>"
For i As Integer = 1 To Products.Count - 1
    Book.Sheets.Add(Products(i))
    Sheet2  = Book.Sheets(Products(i))
    For r As Integer = 0 To Sheet.Rows.Count - 1 '填入数据
        Sheet2.Rows(r).Height = Sheet.Rows(r).Height
        For c As Integer = 0 To Sheet.Cols.Count -1
            Sheet2.Cols(c).Width = Sheet.Cols(c).Width
            Sheet2(r, c).Value = Sheet(r, c).Value
            Sheet2(r, c).Style = Sheet(r, c).Style
        Next
    Next
    Sheet2(1,7).Value = "<出库用途 ='" & Products(i) & "'>"  '写入打印条件='"& Product & "'
Next
Book.Build() '生成报表
Book.Save(fl)
Dim Proc As New Process
Proc.File = fl
Proc.Start()

 回到顶部