以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 复制word (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=127866) |
-- 作者:qaz17909 -- 发布时间:2018/11/23 19:55:00 -- 复制word 有个word文档A,第一行有“文本”二字,现要用openFileDialog,选择一个目标word后,把里面的内容复制粘贴到A中,替换掉“文本”二字。请问代码怎么写? |
-- 作者:有点蓝 -- 发布时间:2018/11/23 20:37:00 -- 读取参考:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=71352&skin=0 |
-- 作者:qaz17909 -- 发布时间:2018/11/23 21:58:00 -- 我基本上已经好了,可以生成我想要的报告,但现在想把生成的报告上传到ftp上,但是提示“文件已被打开,无法上传”,请问哪个地方有问题? Dim t As Table = CurrentTable Dim r As Row = t.Current Dim tm As String = ProjectPath & "Attachments\\报告正文.doc" \'指定模板文件 Dim path As String = ProjectPath & "Reports\\报告正文\\" & r("报告编号") & "\\" If FileSys.DirectoryExists(path) = False Then \'如果目录不存在 FileSys.CreateDirectory(path) \'则建立 End If Dim fl As String = path & r("报告编号") & " " & r("样品类别") & " " & r("委托方") & ".doc" Dim wrt As New WordReport(t,tm,fl) \'定义一个WordReport wrt.Build() \'逐行生成报表 wrt.quit Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog dlg.Filter= "Word文件|*.doc" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim app As New MSWord.Application try Dim doc As Object = app.Documents.Open(dlg.FileName) Dim count = doc.Characters.Count Dim rng As MSWord.Range = Doc.Range(Start:=0, End:=count) rng.Select() \'全选 rng.Copy() \'拷贝 Dim ndoc = app.Documents.Open(fl) If app.ActiveWindow.Selection.Find.Execute("附页未上传") Then app.ActiveWindow.Selection.paste app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.Font.Size = 9 app.ActiveWindow.Selection.TypeText(Text:= r("报告编号")) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument End If app.Visible = False Doc.close app.Documents.Save catch ex As exception msgbox(ex.message) app.Quit finally app.Quit End try End If Dim ftp1 As New FtpClient ftp1.Host= "" ftp1.Account = "" ftp1.Password = "" If ftp1.DirExists("\\报告正文\\" & r("报告编号")) = False Then ftp1.MakeDir("\\报告正文\\" & r("报告编号")) End If Dim tg As String = "\\报告正文\\" & r("报告编号") & "\\" & r("报告编号") & " " & r("样品类别") & " " & r("委托方") & ".doc" If ftp1.Upload(fl,tg) = True Then MessageBox.show("上传完成!") Else MessageBox.show("上传失败") End If |
-- 作者:有点蓝 -- 发布时间:2018/11/23 22:38:00 -- office文件的退出有时候是有一定的时间差的,不是马上就能退出,试试延迟几秒再上传 System.Threading.Thread.Sleep(3000) Dim ftp1 As New FtpClient ……
|
-- 作者:qaz17909 -- 发布时间:2020/10/29 15:47:00 -- 设置延迟3000毫秒对于大部分的文件够用,但有些文档比较大退出慢的时候还是会报错,有没有更加完美的解决办法,判断完全退出后再执行后面的代码? |
-- 作者:有点蓝 -- 发布时间:2020/10/29 16:00:00 -- 没有完美的解决办法。可以写代码直接杀掉word进程,但是可能会导致文件损坏,或者保存失败。 另外提供一个上传按钮,出错后提示用户晚一点手工重新上传
|