Foxtable(狐表)用户栏目专家坐堂 → 打印设置简化代码


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

主题:打印设置简化代码

美女呀,离线,留言给我吧!
联友
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:300 积分:2565 威望:0 精华:0 注册:2013/5/23 9:49:00
打印设置简化代码  发帖心情 Post By:2016/10/19 13:02:00 [只看该作者]

 下面代码能简化吗?

   If  _UserGroup = "校长"  Or _UserGroup = "教导处" Then
        Dim Book As New XLS.Book(ProjectPath & "Attachments\在籍学生基本信息.xls")
        Dim fl As String  = ProjectPath & "Reports\在籍学生基本信息.xls"
        Book.Build()
        Book.Save(fl)
        Dim App As New MSExcel.Application
        Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
        Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
        App.Visible = True
        Ws.PrintPreview
        App.Quit
    Else
        If  _UserGroup = "班主任"  Then
            Dim Book As New XLS.Book(ProjectPath & "Attachments\基本信息.xls")
            Dim fl As String  = ProjectPath & "Reports\基本信息.xls"
            Book.Build()
            Book.Save(fl)
            Dim App As New MSExcel.Application
            Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
            Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
            App.Visible = True
            Ws.PrintPreview
            App.Quit
        End If

End If

[此贴子已经被作者于2016/10/19 13:02:50编辑过]

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


加好友 发短信
等级:一尾狐 帖子:497 积分:4892 威望:0 精华:0 注册:2012/4/20 8:42:00
  发帖心情 Post By:2016/10/19 13:17:00 [只看该作者]

 Dim b1 As String = ProjectPath & "Attachments\在籍学生基本信息.xls"
Dim b2 As String = ProjectPath & "Attachments\基本信息.xls"
Dim f1 As String  = ProjectPath & "Reports\在籍学生基本信息.xls"
Dim f2 As String  = ProjectPath & "Reports\基本信息.xls"
Select Case _UserGroup
    Case "校长","教导处"
        Dim Book As New XLS.Book(b1)
        Book.Build()
        Book.Save(f1)
    Case "班主任"
        Dim Book As New XLS.Book(b2)
        Book.Build()
        Book.Save(f2)
End Select
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
App.Visible = True
Ws.PrintPreview
App.Quit

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


加好友 发短信
等级:超级版主 帖子:110574 积分:562760 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/10/19 14:46:00 [只看该作者]

Dim ename As String

If  _UserGroup = "校长"  Or _UserGroup = "教导处" Then
    ename = "在籍学生基本信息"
Else If  _UserGroup = "班主任"  Then
    ename = "基本信息"
    
End If
If ename > "" Then
    Dim Book As New XLS.Book(ProjectPath & "Attachments\" & ename & ".xls")
    Dim fl As String  = ProjectPath & "Reports\" & ename & ".xls"
    Book.Build()
    Book.Save(fl)
    Dim App As New MSExcel.Application
    Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
    App.Visible = True
    Ws.PrintPreview
    App.Quit
End If

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


加好友 发短信
等级:三尾狐 帖子:788 积分:6297 威望:0 精华:0 注册:2012/6/11 17:21:00
  发帖心情 Post By:2016/12/13 9:10:00 [只看该作者]

谢谢

 回到顶部