【发布时间】:2014-08-18 09:53:53
【问题描述】:
我有一个 Visual Studio 2010 VB.NET 4.0 Windows 应用程序项目。该代码正在填充 Word 2010 文档。有 30 到 60 个表格区域内的任意位置以及 30 到 50 个嵌入式图表区域内的任意位置(均定义为内联形状 (InlineShape))。
我必须开始定期拨打Document.Save(),因为我收到以下错误:There are too many edits in the document. This operation will be incomplete. Save your work.。有足够的可用磁盘空间和内存。
在大多数情况下,.Save() 有效,但在调用.Save() 时会随机显示另存为对话框。附带说明一下,如果我单击取消,则会引发以下错误:Command failed at Microsoft.Office.Interop.Word.DocumentClass.Save()。
这里是代码的摘录,让您了解正在发生的事情:
Imports _word = Microsoft.Office.Interop.Word
...
...
Dim wrd As _word.Application = CreateObject("Word.Application")
wrd.Visible = True
wrd.ScreenUpdating = True
Dim doc As _word.Document = wrd.Documents.Open("C:\my-file-template.docx")
doc.Application.DisplayAlerts = _word.WdAlertLevel.wdAlertsNone
doc.Range.NoProofing = True
Dim reportFilePathName As String = "C:\my-file.docx"
If File.Exists(reportFilePathName) Then
File.Delete(Me.reportFilePathName)
End If
doc.SaveAs2(reportFilePathName)
...
'Numerous tasks carried out
...
doc.Save() 'This may or may not cause the save as dialog to show
...
有人知道为什么会显示另存为对话框吗?我可以阻止它吗?
为什么我收到“编辑过多”错误,因此不需要进行如此多的保存(这无论如何都会减慢处理速度!)?
【问题讨论】:
-
这是您项目中的所有代码/代码吗???它可以在我的电脑上运行。“没有另存为对话框/没有错误”
-
没有。这实际上是一个微小的提取物。它有 100 行代码,分布在各个类中。在我评论说“执行了许多任务”的地方,可能会有 大量 的操作,包括添加文本、格式化、添加图表、向表格添加行等。我的直觉是真正的问题围绕“文档中的编辑过多”错误,这迫使我保存 - 也许保存的频率正在吹掉 Word...
-
我会说问题出在“执行的许多任务”中
-
为什么对这个问题投反对票???我可以知道为什么这样我可以在未来改进我的问题......
标签: vb.net ms-word ole-automation