问题描述
我已经编写了以下代码来编辑Word文档的书签.由于生成了文档,因此可以看到doc,但是如果我关闭该文档并再次尝试打开同一doc,则doc单词会出现错误,如下所示:
1.检查文件权限以获取文件/驱动器.
2.确保有足够的内存和磁盘空间.
私有void GenerateApplication()
{
对象readOnly = true;
对象修复=假;
对象bookMarkName ="applicantName";
对象bookMarkCompany ="firmName";
对象bookMarkPost ="postName";
fielName = @"C:\ Documents and Settings \ All Users \ Desktop \ OperateWordFromC#.dotx";
objDoc = wordApp.Documents.Open(ref fielName,ref missingValuesValues,ref readOnly,ref missingValuesValues,ref missingValuesValues,
ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,
ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,ref repair,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues);
objDoc.Activate();
objDoc.Bookmarks.get_Item(ref bookMarkName).Range.Text = txtApplicantName.Text;
objDoc.Bookmarks.get_Item(ref bookMarkCompany).Range.Text = txtAppliedCompany.Text;
objDoc.Bookmarks.get_Item(ref bookMarkPost).Range.Text = txtAppliedPost.Text;
字符串outputFile = @"C:\ Documents and Settings \ All Users \ Desktop \ ApplicationOf-" + txtApplicantName.Text +".docx";
bookMarkName = null;
bookMarkCompany = null;
bookMarkPost = null;
对象objSaveAsFile = outputFile;
对象objFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
wordApp.ActiveDocument.SaveAs(ref objSaveAsFile,ref repair,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,
ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,
ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues,ref missingValuesValues);
wordApp.Visible = true;
}
I have written following Code to edit bookmarks of Word document., as document is generated doc is visible but if i close the same and tried to open the same doc again the word doc gives error as :
1.Check file permissions for file/ drive.
2.make sure there is sufficient memory and disk space.
private void GenerateApplication()
{
object readOnly = true;
object repair = false;
object bookMarkName = "applicantName";
object bookMarkCompany = "firmName";
object bookMarkPost = "postName";
fielName = @"C:\Documents and Settings\All Users\Desktop\OperateWordFromC#.dotx";
objDoc = wordApp.Documents.Open(ref fielName, ref missingValuesValues, ref readOnly, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref repair, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues);
objDoc.Activate();
objDoc.Bookmarks.get_Item(ref bookMarkName).Range.Text = txtApplicantName.Text;
objDoc.Bookmarks.get_Item(ref bookMarkCompany).Range.Text = txtAppliedCompany.Text;
objDoc.Bookmarks.get_Item(ref bookMarkPost).Range.Text = txtAppliedPost.Text;
string outputFile = @"C:\Documents and Settings\All Users\Desktop\ApplicationOf-" + txtApplicantName.Text + ".docx";
bookMarkName = null;
bookMarkCompany = null;
bookMarkPost = null;
Object objSaveAsFile = outputFile;
Object objFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
wordApp.ActiveDocument.SaveAs(ref objSaveAsFile, ref repair, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues,
ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues, ref missingValuesValues);
wordApp.Visible = true;
}
推荐答案
这篇关于在C#中编辑后无法打开文档文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!