以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]图片生成Word  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=142807)

--  作者:天一生水
--  发布时间:2019/11/6 19:53:00
--  [求助]图片生成Word
老师好!
图片转Word时遇到两个问题:
1、图片插入专业报表,然后从专业报表再另存为Word文档时,如果图片较多(超过100张)或者图片较大(每张1M),图片就无法有效插入,专业报表就成空白的了;
2、下面的加黑的部分代码,是先从专业报表保存为HTML格式,再存为Word格式。如果使用,前面设置的页边距和图片大小等就不起作用了,是什么原因?

Dim doc As New PrintDoc \'定义一个报表对象
Doc.PageSetting.PaperKind = 9   \'A4纸张编码
Doc.PageSetting.LeftMargin = 0.5   \'页边距
Doc.PageSetting.BottomMargin = 0.5
Doc.PageSetting.rightMargin = 0.5
Doc.PageSetting.TopMargin = 0.5

Dim dlg As New OpenFileDialog
dlg.MultiSelect = True
dlg.Filter= "图片文件|*.jpg"
dlg.Title = "添加图片"   \'对话窗口名称
dlg.InitialDirectory = ProjectPath & "Attachments\\文档"   \'默认打开路径
If dlg.ShowDialog = DialogResult.OK Then
    For Each fl As String In dlg.FileNames     \'遍历添加        
        Dim rm As New prt.RenderImage   \'定义一个图片对象
        rm.Image = GetImage(fl)   \'设置图片
        rm.Width = "Parent.Width"   \'宽度等于页面宽度
        rm.Height = "Auto"    \'高度由图片大小自动决定
        \'rm.Style.ImageAlign.StretchHorz = False   \'禁止图片水平拉伸-不要用
        rm.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center   \'居中显示
        doc.Body.Children.Add(rm)   \'将图片对象加入报表
        \'rm.BreakBefore = prt.BreakEnum.Page \'打印前换页        
    Next
    \'Doc.Preview() \'预览
    
    doc.SaveHTM("d:\\test.doc")    \'保存为HTML格式
    Dim strs As String = FileSys.ReadAllText("d:\\test.doc")
    Dim idx As Integer = strs.IndexOf("<html")
    strs = strs.SubString(idx)
    FileSys.WriteAllText("d:\\test.doc", strs, False)    \'是否追加写入
    
End If

--  作者:有点蓝
--  发布时间:2019/11/7 9:51:00
--  
网页的格式是比较特殊的,并不是说把扩展名改为doc,就能变成word文档了。

试了一下,找不到什么好的办法