Foxtable(狐表)用户栏目专家坐堂 → 代码


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

主题:代码

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


加好友 发短信
等级:六尾狐 帖子:1470 积分:8981 威望:0 精华:0 注册:2013/10/24 9:12:00
  发帖心情 Post By:2015/4/27 16:49:00 [只看该作者]

    Dim App As New MSExcel.Application
    Dim wb As MSExcel.WorkBook = App.WorkBooks.open(f1)
    For Each Ws As MSExcel.WorkSheet In Wb.WorkSheets    '
        If ws.name = "分户快报" Then
            For n1 As Integer = 3 To 5
                For n2 As Integer = 4 To 48
                    If ws.cells(n2+1,n1+1).Formula = "" Then
                        ws.cells(n2+1,n1+1).Value = val(Sheet1(n2,n1).Value)
                    End If
                Next
            Next
        End If
        If ws.name = "资产负债表" Then
            ws.cells(4,1).Value = Sheet2(3,0).Value   '单位名称
            ws.cells(2,1).Value = Sheet2(1,0).Value   '日期
            For n1 As Integer = 2 To 3
                For n2 As Integer = 5 To 54
                    If ws.cells(n2+1,n1+1).Formula = "" Then
                        ws.cells(n2+1,n1+1).Value = val(Sheet2(n2,n1).Value)
                    End If
                    If ws.cells(n2+1,n1+5).Formula = "" Then
                        ws.cells(n2+1,n1+5).Value = val(Sheet2(n2,n1+4).Value)
                    End If
                Next
            Next
        End If
        If ws.name = "利润及分配表" Then
            For n1 As Integer = 2 To 3
                For n2 As Integer = 6 To 35
                    If ws.cells(n2+1,n1+1).Formula = "" Then
                        ws.cells(n2+1,n1+1).Value = val(Sheet3(n2,n1).Value)
                    End If
                    If ws.cells(n2+1,n1+5).Formula = "" Then
                        ws.cells(n2+1,n1+5).Value = val(Sheet3(n2,n1+4).Value)
                    End If
                Next
            Next
        End If
        If ws.name = "费用表" Then
            For n1 As Integer = 3 To 6
                For n2 As Integer = 4 To 32
                    If ws.cells(n2+1,n1+1).Formula = "" Then
                        ws.cells(n2+1,n1+1).Value = val(Sheet4(n2,n1).Value)
                    End If
                Next
            Next
        End If
        If ws.name = "工资月报" Then
            For n1 As Integer = 3 To 4
                For n2 As Integer = 4 To 24
                    If ws.cells(n2+1,n1+1).Formula = "" Then
                        ws.cells(n2+1,n1+1).Value = val(Sheet5(n2,n1).Value)
                    End If
                Next
            Next
        End If
        If ws.name = "附列资料" Then
            For n1 As Integer = 1 To 13
                For n2 As Integer = 2 To 19
                    If ws.cells(n2+1,n1+1).Formula = "" Then
                        ws.cells(n2+1,n1+1).Value = val(Sheet6(n2,n1).Value)
                    End If
                Next
            Next
        End If
    Next
代码中 If ws.name = "分户快报" Then,如何先判断“分户快报” 是否存在?

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


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2015/4/27 16:51:00 [只看该作者]

你这样判断,不存在就不会进入IF条件了

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


加好友 发短信
等级:六尾狐 帖子:1470 积分:8981 威望:0 精华:0 注册:2013/10/24 9:12:00
  发帖心情 Post By:2015/4/27 21:38:00 [只看该作者]

用代码如何判断是否存在某一工作表?

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


加好友 发短信
等级:六尾狐 帖子:1470 积分:8981 威望:0 精华:0 注册:2013/10/24 9:12:00
  发帖心情 Post By:2015/4/27 21:46:00 [只看该作者]

代码中 If ws.name = "分户快报" Then,如何先判断sheet1是否存在?

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


加好友 发短信
等级:六尾狐 帖子:1470 积分:8981 威望:0 精华:0 注册:2013/10/24 9:12:00
  发帖心情 Post By:2015/4/28 9:38:00 [只看该作者]

Dim c As Date = vars("cc")
Dim y As Integer = c.year
Dim m As Integer = c.month
Dim n As Integer = 1
Dim f0 As String = "E:\快盘\另存报表"                         '存放地址
Dim f1 As String = "E:\财务数据汇总\模板\基层报表模板.xls"    '选择模板
Dim f2 As String = e.Form.Controls("Label4").Text             '选择报表
Dim Book1 As New XLS.Book(f2)
Dim Sheet2 As XLS.Sheet = Book1.Sheets("资产负债表")
Dim s As String  = Sheet2(3,0).Value
Dim tt As Table = Tables("单位")
For i1 As Integer = 0 To tt.Rows.Count - 1
    If s.Contains(tt.Rows(i1)("单位1")) Then
        s = tt.Rows(i1)("单位2")
        Exit For
    End If
Next
Dim f3 As String = f0 & "\" & s & y & Format(m,"00") & ".xls"
messagebox.show(f3)
If FileSys.FileExists(f3) Then
    If MessageBox.Show(s & "公司报表已另存,是否重新另存?","确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) =DialogResult.OK Then
        FileSys.DeleteFile(f3)
    End If
End If
If not FileSys.FileExists(f3) Then
    Dim str As String
    Dim App1 As New MSExcel.Application
    Dim wb1 As MSExcel.WorkBook = App1.WorkBooks.open(f2)
    For Each Ws As MSExcel.WorkSheet In Wb1.WorkSheets    '
        str = str + ws.name + ","
    Next
    wb1.close
    App1.Quit
    Dim App As New MSExcel.Application
    Dim wb As MSExcel.WorkBook = App.WorkBooks.open(f1)
    For Each Ws As MSExcel.WorkSheet In Wb.WorkSheets    '
        If ws.name = "分户快报" Then
            If str.Contains("分户快报") Then
                Dim Sheet1 As XLS.Sheet = Book1.Sheets("分户快报")
                For n1 As Integer = 3 To 5
                    For n2 As Integer = 4 To 48
                        If ws.cells(n2+1,n1+1).Formula = "" Then
                            ws.cells(n2+1,n1+1).Value = val(Sheet1(n2,n1).Value)
                        End If
                    Next
                Next
            Else
                ws.delete
            End If
        End If
        If ws.name = "资产负债表" Then
            If str.Contains("资产负债表") Then
                ws.cells(4,1).Value = Sheet2(3,0).Value   '单位名称
                ws.cells(2,1).Value = Sheet2(1,0).Value   '日期
                For n1 As Integer = 2 To 3
                    For n2 As Integer = 5 To 54
                        If ws.cells(n2+1,n1+1).Formula = "" Then
                            ws.cells(n2+1,n1+1).Value = val(Sheet2(n2,n1).Value)
                        End If
                        If ws.cells(n2+1,n1+5).Formula = "" Then
                            ws.cells(n2+1,n1+5).Value = val(Sheet2(n2,n1+4).Value)
                        End If
                    Next
                Next
            Else
                ws.delete
            End If
        End If
        If ws.name = "利润及分配表" Then
            If str.Contains("利润及分配表") Then
                Dim Sheet3 As XLS.Sheet = Book1.Sheets("利润及分配表")
                For n1 As Integer = 2 To 3
                    For n2 As Integer = 6 To 35
                        If ws.cells(n2+1,n1+1).Formula = "" Then
                            ws.cells(n2+1,n1+1).Value = val(Sheet3(n2,n1).Value)
                        End If
                        If ws.cells(n2+1,n1+5).Formula = "" Then
                            ws.cells(n2+1,n1+5).Value = val(Sheet3(n2,n1+4).Value)
                        End If
                    Next
                Next
            Else
                ws.delete
            End If
        End If
        If ws.name = "费用表" Then
            If str.Contains("费用表") Then
                Dim Sheet4 As XLS.Sheet = Book1.Sheets("费用表")
                For n1 As Integer = 3 To 6
                    For n2 As Integer = 4 To 32
                        If ws.cells(n2+1,n1+1).Formula = "" Then
                            ws.cells(n2+1,n1+1).Value = val(Sheet4(n2,n1).Value)
                        End If
                    Next
                Next
            Else
                ws.delete
            End If
        End If
        If ws.name = "工资月报" Then
            If str.Contains("工资月报") Then
                Dim Sheet5 As XLS.Sheet = Book1.Sheets("工资月报")
                For n1 As Integer = 3 To 4
                    For n2 As Integer = 4 To 24
                        If ws.cells(n2+1,n1+1).Formula = "" Then
                            ws.cells(n2+1,n1+1).Value = val(Sheet5(n2,n1).Value)
                        End If
                    Next
                Next
            Else
                ws.delete
            End If
        End If
        If ws.name = "附列资料" Then
            If str.Contains("附列资料") Then
                Dim Sheet6 As XLS.Sheet = Book1.Sheets("附列资料")
                For n1 As Integer = 1 To 13
                    For n2 As Integer = 2 To 19
                        If ws.cells(n2+1,n1+1).Formula = "" Then
                            ws.cells(n2+1,n1+1).Value = val(Sheet6(n2,n1).Value)
                        End If
                    Next
                Next
            Else
                ws.delete
            End If
        End If
    Next
    FileSys.DeleteFile(f2)
    For Each Ws As MSExcel.WorkSheet In Wb.WorkSheets
        ws.UsedRange.Formula = ws.UsedRange.Formula
        ws.Activate
        app.ActiveWindow.DisplayZeros = False
    Next
    wb.saveas(f3)
    wb.close
    App.Quit
    messagebox.show("另存报表成功!")
End If

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


加好友 发短信
等级:六尾狐 帖子:1470 积分:8981 威望:0 精华:0 注册:2013/10/24 9:12:00
  发帖心情 Post By:2015/4/28 9:39:00 [只看该作者]

这样做是不是很麻烦?

 回到顶部
总数 36 上一页 1 2 3 4