本文介绍了word automation vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我一直在构建一个应用程序,它将文本文件中的字段与 a字模板合并,将生成的word文件保存到用户的硬盘中, 然后通过电子邮件将文件作为附件发送。 我遇到的问题是我无法删除我在 由于文件被电子邮件进程锁定而导致进程结束。由于病毒检查,似乎比完成代码需要的时间更长 软件在发布之前拦截邮件(至少那是什么 我把它缩小到了。) 我不想在代码完成后留下文件。而且我不想我想要阻止完成代码流程,直到发送 电子邮件,以防电子邮件进程在某些机器上花费的时间超过 其他人。 我不确定是否有更好的方法来处理代码中的附件 so我没有必要将文件保存到用户的桌面。或者,如果我可以使用 deattach进程,我可以从代码触发,以便稍后删除该文件。或者 别的东西。 我附上了以下代码的片段: 谢谢 Steve ------------ WordDoc.SaveAs(sSaveFileName) 做的不是WordDoc.Saved Application.DoEvents() 循环 WordDoc.Close(Word。 WdSaveOptions.wdDoNotSaveChange s) ''通过电子邮件发送已保存的合并文档。 Dim Fromaddress As New MailAddress(fromaddress) Dim Toaddress As New MailAddress(" toaddress") Dim myMail As New MailMessage(Fromaddress,ToAddress) myMail.Subject =" test" ; Dim AttachmentFile As Attachment = New Attachment(sSaveFileName) myMail.Attachments.Add(AttachmentFile) myMail.Priority = MailPriority.High Dim client As New SmtpClient client.Host =" hostaddress" client.Send(myMail) > ''发布参考文献。 WordMailMerge =没什么 WordDoc =没什么 WordApp =没什么 ''删除临时文件。 System.IO.File.Delete(sSaveFileName) 解决方案 你的WordDoc.Close后你需要一个WordDoc.Quit。 _________________________________ 死神 史蒂夫 < s。***** @ comcast.netwrote in message news:eO ************** @ TK2MSFTNGP03.phx.gbl ... I''ve been building an application that will merge fields in a text file witha word template, save the resulting word file out to the user''s hard drive,and then email the file as an attachment.The problem I''m having is that I can''t delete the word file I saved at theend of the process due to the file being locked by the email process. Itappears to take longer than the code takes to complete due to virus checkingsoftware that intercepts the mail before releasing it (at least that''s whatI''ve narrowed it down to).I don''t want to leave the file around after the code has completed. And Idon''t think I want to hold up the completion of the code process until theemail gets sent in case the email process takes longer on some machines thanothers.I''m not sure if there is a better way to handle the attachment in the codeso I don''t have to save a file to the user''s desktop. Or if I can use adeattach process that I can trigger from code to delete the file later. Orsomething else.I''ve attached a snippet of the code below:ThanksSteve------------WordDoc.SaveAs(sSaveFileName)Do While Not WordDoc.SavedApplication.DoEvents()LoopWordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChange s)'' Email the Saved Merge Document.Dim Fromaddress As New MailAddress("fromaddress")Dim Toaddress As New MailAddress("toaddress")Dim myMail As New MailMessage(Fromaddress, ToAddress)myMail.Subject = "test"Dim AttachmentFile As Attachment = New Attachment(sSaveFileName)myMail.Attachments.Add(AttachmentFile)myMail.Priority = MailPriority.HighDim client As New SmtpClientclient.Host = "hostaddress"client.Send(myMail)'' Release the references.WordMailMerge = NothingWordDoc = NothingWordApp = Nothing'' Delete the temporary files.System.IO.File.Delete(sSaveFileName) 解决方案 这篇关于word automation vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-31 08:31