Foxtable(狐表)用户栏目专家坐堂 → [求助]html编辑器图文打印


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

主题:[求助]html编辑器图文打印

帅哥哟,离线,有人找我吗?
天一生水
  11楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1137 积分:11224 威望:0 精华:0 注册:2017/9/26 16:30:00
  发帖心情 Post By:2019/3/3 17:02:00 [只看该作者]

老师好!
我想以“页面视图“的模式打开word,应该怎样设置?
Dim Proc As New Process '定义一个新的Process
Proc.File = ProjectPath & "新模板.doc"   '指定要打开的文件
Proc.Start()

这是VBA代码,怎样用?
ActiveWindow.ActivePane.View.Type = wdPrintView页面视图

谢谢!


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


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

比如

 

Dim app As New MSWord.Application
try
    Dim fileName = "d:\test.doc"
    Dim doc As Object = app.Documents.Open(fileName)
   
    app.ActiveWindow.ActivePane.View.Type  = MSWord.WdViewType.wdPrintView
   
    app.Visible = True

catch ex As exception
    msgbox(ex.message)
    app.Quit
End try


 回到顶部
帅哥哟,离线,有人找我吗?
天一生水
  13楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1137 积分:11224 威望:0 精华:0 注册:2017/9/26 16:30:00
  发帖心情 Post By:2019/3/6 22:10:00 [只看该作者]

甜老师好!
10楼的代码,在项目所在的目录下生成word文件时,word中的图片显示没有问题。
但是如果把生成的word更换路径,word文件中的图片就显示不出来了。
能不能在生成word文件时,把图片直接粘贴进word中,而不是仅仅是图片的链接。

1、代码

 

Dim mb As String = FileSys.ReadAllText(ProjectPath & "初始模板.html")
Dim tbl As Table = Tables("通知单")          '选中的多行
Dim str As String = ""
For i As Integer = tbl.TopRow To tbl.BottomRow
    Dim s = mb
    Dim r As Row = tbl.Rows(i)
    str &= s.Replace("(绑定编号)",r("编号")).Replace("(绑定html_内容)",r("html_内容")).Replace("../","./")
Next
str = "<body><html>" & str & "</body></html>"
FileSys.WriteAllText(ProjectPath & "新模板.doc", str, False)
Dim Proc As New Process '定义一个新的Process
Proc.File = ProjectPath & "新模板.doc"   '指定要打开的文件
Proc.Start()


2、模板


<p align="left" style="text-indent:0em;">
 <strong>【编号信息】</strong>
</p>
<p align="left" style="text-indent:0em;">
 (绑定编号)
</p>
<p align="left" style="text-indent:0em;">
 <strong>【题目内容】</strong>
</p>
<p align="left" style="text-indent:0em;">
 (绑定html_内容)
</p>


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


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

插入图片的时候,直接嵌入图片,如

 

Tables(e.Form.TableName).current("html_内容") = EditorHelper.BodyHtml
'******复制新文件*********
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "图片文件|*.bmp;*.jpg;*.gif;*.png;*.jpeg;*.tiff" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    '********调用html编辑器***********
    Dim wbs1 As Object = e.Form.Controls("WebBrowser1").basecontrol
    wbs1.Url = new System.Uri(ProjectPath & "kindeditor\e.html", System.UriKind.Absolute)
    EditorHelper = new ObjectForScriptingHelper
    wbs1.ObjectForScripting = EditorHelper
    '修改html内容
    Dim wb As new WeUI
    Dim base64 = wb.ImageToBase64(getimage(dlg.FileName))
    With Tables(e.Form.TableName)
        .Current("html_内容") = .Current("html_内容") & "<img alt="""" src=""" & base64 & """ /><p>"
        EditorHelper.RequestContent( .current("html_内容"))
    End With
End If
'
Dim wbs As Object = e.Form.Controls("WebBrowser1").basecontrol
wbs.Url = new System.Uri(ProjectPath & "kindeditor\e.html", System.UriKind.Absolute)
EditorHelper = new ObjectForScriptingHelper
wbs.ObjectForScripting = EditorHelper
''修改html内容
With Tables("通知单")
    EditorHelper.RequestContent( .current("html_内容"))
End With


 回到顶部
帅哥哟,离线,有人找我吗?
天一生水
  15楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1137 积分:11224 威望:0 精华:0 注册:2017/9/26 16:30:00
  发帖心情 Post By:2019/3/7 16:48:00 [只看该作者]

谢谢甜老师!

但是嵌入图片后,写入html文件可以显示图片,写入Word文件不能显示图片。

将这样生成的html文件用Word方式打开,也不能显示图片,但用浏览器直接打开却可以。

是什么原因?

 

Dim mb As String = FileSys.ReadAllText(ProjectPath & "初始模板.html")
Dim tbl As Table = Tables("通知单")          '选中的多行
Dim str As String = ""
For i As Integer = tbl.TopRow To tbl.BottomRow
    Dim s = mb
    Dim r As Row = tbl.Rows(i)
    str &= s.Replace("(绑定编号)",r("编号")).Replace("(绑定html_内容)",r("html_内容"))
Next
str = "<body><html>" & str & "</body></html>"
FileSys.WriteAllText(ProjectPath & "新模板.doc", str, False)      '这个不显示图片

FileSys.WriteAllText(ProjectPath & "新模板.html", str, False)    '这个显示图片正常
Dim Proc As New Process '定义一个新的Process
Proc.File = ProjectPath & "新模板.doc"   '指定要打开的文件
Proc.Start()


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


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

1、不需要修改之前的插入图片方式;

 

2、修改保存代码,如

 

'''
Dim mb As String = FileSys.ReadAllText(ProjectPath & "初始模板.html")
Dim tbl As Table = Tables("通知单")          '选中的多行
Dim str As String = ""
For i As Integer = tbl.TopRow To tbl.BottomRow
    Dim s = mb
    Dim r As Row = tbl.Rows(i)
    str &= s.Replace("(绑定编号)",r("编号")).Replace("(绑定html_内容)",r("html_内容")).Replace("../","./")
Next
str = "<body><html>" & str & "</body></html>"
FileSys.WriteAllText(ProjectPath & "新模板.doc", str, False)
Dim app As new msword.application
Dim Doc = app.Documents.open(ProjectPath & "新模板.doc")
Doc.saveas(FileName:=projectpath & "test123.doc", FileFormat:=0)
app.visible = True


 回到顶部
帅哥哟,离线,有人找我吗?
天一生水
  17楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1137 积分:11224 威望:0 精华:0 注册:2017/9/26 16:30:00
  发帖心情 Post By:2019/3/20 8:22:00 [只看该作者]

甜老师好!

遇到一个新问题,我将截图插入html编辑器中的图片拖拽至合适尺寸后,通过替换html模板的方法生成Word文件,图片在Word中又恢复成原始尺寸,怎样处理?

谢谢!

 


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

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


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

1、你这种是正常情况,转换成word的时候,没有图片大小信息,没办法处理的。

 

2、具体问题,做一个实例发上来测试。


 回到顶部
帅哥哟,离线,有人找我吗?
天一生水
  19楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1137 积分:11224 威望:0 精华:0 注册:2017/9/26 16:30:00
  发帖心情 Post By:2019/3/20 11:44:00 [只看该作者]

请老师看实例:

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:测试html图文word.rar


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


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

如下代码

 

'''
If DataTables("通知单").Select("标注 = true").count = 0 Then
    Dim Result As DialogResult
    Result = MessageBox.Show("你没有选中数据,请勾选复选框!"& vbcrlf &"是---返回"& vbcrlf &"否---关闭", "提示",  MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If Result = DialogResult.Yes Then
        Return
    Else
        Return
    End If
End If

If DataTables("通知单").Select("标注 = true").count > 0 Then
    For Each r As Row In Tables("通知单")    '显示标注
        Tables("通知单").Filter = "标注 = True"
    Next
   
    Dim mb As String = FileSys.ReadAllText(ProjectPath & "初始模板.html")
    Dim tbl As Table = Tables("通知单")          '选中的多行
    Dim str As String = ""
    'For i As Integer = tbl.TopRow To tbl.BottomRow
    For Each r As DataRow In DataTables("通知单").Select("标注 = true")
        Dim s = mb
        'Dim r As Row = tbl.Rows(i)
        str &= s.Replace("(绑定编号)",r("编号")).Replace("(绑定html_内容)",r("html_内容")).Replace("../","./").Replace("(绑定html_要求)",r("html_要求")).Replace("../","./")
    Next
   
    Dim txt As String = str
    Dim pattern As String = "<img .+?/>"
   
    Dim rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
    For Each  match As System.Text.RegularExpressions.Match In rgx.Matches(txt)
        Dim s As String = match.Value
        Dim w As Integer = -1
        Dim h As Integer = -1
        Dim mc = System.Text.RegularExpressions.Regex.Matches(s, "(?<=width:)[0-9]+(?=px)")
        If mc.count > 0 Then
            w = mc(0).value
        End If
        mc = System.Text.RegularExpressions.Regex.Matches(s, "(?<=height:)[0-9]+(?=px)")
        If mc.count > 0 Then
            h = mc(0).value
        End If
        If w <> -1 Then
            s = System.Text.RegularExpressions.Regex.replace(s, "width=\"".*?\""", "width=""" & w & """")
            s = System.Text.RegularExpressions.Regex.replace(s, "height=\"".*?\""", "height=""" & h & """")
            'msgbox(s)
            str = str.replace(match.Value, s)
        End If
    Next
   

   
    str = "<body><html>" & str & "</body></html>"
    FileSys.WriteAllText(ProjectPath & "新模板.doc", str, False)
End If

Dim app As New MSWord.Application
Dim Doc = app.Documents.open(ProjectPath & "新模板.doc")
Doc.saveas(FileName:=projectpath & "Attachments/" & "新.doc", FileFormat:=0)
app.ActiveWindow.ActivePane.View.Type  = MSWord.WdViewType.wdPrintView
app.visible = True


 回到顶部
总数 20 上一页 1 2