Foxtable(狐表)用户栏目专家坐堂 → [求助]Excel报表的页眉中能插入图片吗?


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

主题:[求助]Excel报表的页眉中能插入图片吗?

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


加好友 发短信
等级:四尾狐 帖子:995 积分:6712 威望:0 精华:0 注册:2015/1/12 22:12:00
  发帖心情 Post By:2017/8/15 9:56:00 [只看该作者]

谢谢老师,再提个要求,看能不能做到:

    就是在预览和预览后关闭时,能不能控制不要闪一下Excel编辑页面

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/8/15 10:23:00 [只看该作者]

回复31楼,这个做不到,显示预览等,都是需要先显示excel编辑页面的。


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


加好友 发短信
等级:四尾狐 帖子:995 积分:6712 威望:0 精华:0 注册:2015/1/12 22:12:00
  发帖心情 Post By:2017/8/15 10:31:00 [只看该作者]

好的,谢谢

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


加好友 发短信
等级:四尾狐 帖子:995 积分:6712 威望:0 精华:0 注册:2015/1/12 22:12:00
  发帖心情 Post By:2017/8/16 8:58:00 [只看该作者]

老师:还有Word模板的问题要请教。代码如下,执行后出现错误如2个图片所示
        Dim tp As Boolean = False
        Dim dpi = basemainform.CreateGraphics.dpiX
        Dim sz() As String
        If tb.Cols.Contains("部门编号") = True Then
            sz = Functions.Execute("dwcjgq",tb.Current("部门编号")).split("|")
        End If
        Dim mb,str,tm,fl As String
        If tb.Cols.Contains("审核人") = True AndAlso tb.Current("审核人").trim(" ") <> "" Then
            mb = "_已审核"
        End If
        '----------------------------------------------------------------------------------------------------
        '选择模板
        Select Case tb.name
            Case "请修任务"
                tm = ProjectPath & "Attachments\报表模板\请修派工单模板.xls"
            Case "房屋台账"
                str = ProjectPath & "Attachments\报表模板\房屋台账模板.doc"
                tm = str.SubString(0,str.Length-4) & mb & str.SubString(str.Length-4,4)   '指定模板文件
            Case "房屋春检表"
                str = ProjectPath & "Attachments\报表模板\房屋春检调查表模板.xls"
                tm = str.SubString(0,str.Length-4) & mb & str.SubString(str.Length-4,4)   '指定模板文件
            Case "公建春检表"
                str = ProjectPath & "Attachments\报表模板\公建春检调查表模板.xls"
                tm = str.SubString(0,str.Length-4) & mb & str.SubString(str.Length-4,4)   '指定模板文件
        End Select
        If FileSys.FileExists(tm) = False Then
            Messagebox.Show("报表模板文件【" & tm & "】不存在 !" & vblf & "请联系系统超级管理员 !","提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        End If
        '----------------------------------------------------------------------------------------------------
        '根据不同类型的模板,选择不同的程序段
        If tm.EndsWith(".xls") Then

        ElseIf tm.EndsWith(".doc") Then
            fl = ProjectPath & "Attachments\报表模板\$$$临时文件.doc" '指定目标文件
            If FileIsOpened(fl)= True Then
                ShowAppWindow("$$$临时文件.doc",5)  '关闭打开的文件
            End If
            Dim app As MSWord.Application
           ' Dim Doc As Documents
            Dim wrt As New WordReport(tb,tm,fl) '定义一个WordReport
            try
                wrt.replace("tihuan单位简称",sz(1))
                wrt.replace("tihuan所属车间",sz(3))
                wrt.replace("tihuan所属工区",sz(5))
                wrt.replace("tihuan打印人",_UserTag)
                wrt.replace("tihuan打印时间",Format(MyDate,"yyyy年MM月dd日"))
                Select Case tb.name
                    Case "房屋台账"
                        Dim file As String = ProjectPath & "RemoteFiles\" & tb.Current("照片")
                        Dim img As image = getImage(file)
                        Dim ZPwidth As Integer = img.width  '照片原始宽度  像素
                        Dim ZPheight As Integer = img.height  '照片原始高度  像素
                        Dim Docwidth As Integer =  324-4  '324磅=432像素  '模板照片框宽度   磅 1像素 = 3/4磅
                        Dim Docheight As Integer = 256-10   '256磅=336像素6 '模板照片框高度   磅 1像素 = 3/4磅
                        Dim bl,Wbl,Hbl As Double  '原始图片像素和模板照片框比例
                        Wbl = ZPwidth/Docwidth
                        Hbl = ZPheight/Docheight
                        Dim width,height As Integer
                        If ZPwidth <= Docwidth AndAlso ZPheight <= Docheight Then
                            width = ZPwidth
                            height = ZPheight
                        ElseIf ZPwidth > Docwidth AndAlso ZPheight <= Docheight Then
                            width = ZPwidth
                            height = Cint(ZPheight/Wbl)
                        ElseIf ZPwidth <= Docwidth AndAlso ZPheight > Docheight Then
                            width = Cint(ZPwidth/Hbl)
                            height = Docheight
                        ElseIf ZPwidth > Docwidth AndAlso ZPheight > Docheight Then
                            If Wbl >= Hbl Then
                                width = Cint(ZPwidth/Wbl)
                                height = Cint(ZPheight/Wbl)
                            Else
                                width = Cint(ZPwidth/Hbl)
                                height = Cint(ZPheight/Hbl)
                            End If
                        End If
                        wrt.ReplaceWithImage("Tihuan照片",file, width, height)
                End Select
                If tb.Current("审核人").trim(" ") <> "" Then
                    wrt.replace("未审核.png","已审核.png")
                End If
                wrt.Build() '逐行生成报表
                wrt.Quit() '退出
                app = New MSWord.Application
                Dim Doc = app.Documents.Open(fl)
                app.DisplayAlerts = False  
                Doc.saved = True  
                app.visible = True
                ShowAppWindow("$$$临时文件.doc",2)   
                If e.StripItem.Name = "预览" Then
                    Doc.PrintPreview
                Else
                    Doc.printout
                End If
            catch ex As exception
                MessageBox.Show(ex.message,"提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            finally

                App.Quit
            End try

        End If




[此贴子已经被作者于2017/8/16 8:58:31编辑过]

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


加好友 发短信
等级:四尾狐 帖子:995 积分:6712 威望:0 精华:0 注册:2015/1/12 22:12:00
  发帖心情 Post By:2017/8/16 8:59:00 [只看该作者]

出错图片如下

图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看
点取消,出现下面出错信息,点重试,返回程序

图片点击可在新窗口打开查看此主题相关图片如下:2.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2017/8/16 9:01:05编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/8/16 9:12:00 [只看该作者]

 你应该还有没退出的word进程。你调出任务管理器,把word进程都结束掉。笨办法是,你注销电脑重新进入。
[此贴子已经被作者于2017/8/16 9:12:05编辑过]

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


加好友 发短信
等级:四尾狐 帖子:995 积分:6712 威望:0 精华:0 注册:2015/1/12 22:12:00
  发帖心情 Post By:2017/8/16 9:20:00 [只看该作者]

进程结束掉了,但每次执行都是这样。代码中应该还缺少点什么

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/8/16 9:22:00 [只看该作者]

 做个例子发上来测试。

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


加好友 发短信
等级:四尾狐 帖子:995 积分:6712 威望:0 精华:0 注册:2015/1/12 22:12:00
  发帖心情 Post By:2017/8/16 10:02:00 [只看该作者]

例子发上来了,请老师看看
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.zip


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/8/16 11:01:00 [只看该作者]

            catch ex As exception
                MessageBox.Show(ex.message,"提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
                App.Quit
            finally
                'If FileIsOpened(fl)= True Then
                'ShowAppWindow("$$$临时文件.doc",5)  '关闭打开的文件
                'End If
            End try
        Else
            Messagebox.Show("报表模板文件类型不正确 !" & vblf & "请联系系统超级管理员 !","提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        End If
        '----------------------------------------------------------------------------------------------------
        '删除临时文件
        Do While True
            If delfile = True Then
                If FileSys.FileExists(fl) Then
                    try
                        io.File.Delete(fl)
                    catch ex As exception
                        application.Doevents
                    End try
                Else
                    Exit Do
                End If
            End If
        Loop

 回到顶部
总数 44 上一页 1 2 3 4 5 下一页