问题一:我在C#中调用word模板,模板中有相应的标签;在word中生成一个表格,程序如下:
object missingValue = Type.Missing;
Word.Range rng = oDoc.Books.get_Item(ref grid).Range;
oDoc.Tables.Add(rng, 3, 4, ref missingValue, ref missingValue);
这个没有问题,可是我在打印预览的时候,表格却不能显示,表格里的内容到是可以显示,不知道这是为什么?
问题二:
我屏蔽了word的复制,粘贴,使word为只读状态;但是有一个问题,就是word中的表格里的数据有时会
超出单元格的大小,显示内容不全,这样我就想可以在word中调整单元格的大小,可是屏蔽后,就不能实现了,不知道有没有解决的办法?程序如下:
//限制word文档不能复制、粘贴功能,只能被查看
            if (oWord.ActiveDocument.ProtectionType == Word.WdProtectionType.wdNoProtection)
            {
                object missing = Type.Missing;
                oWord.ActiveDocument.Protect(Word.WdProtectionType.wdAllowOnlyComments, ref missing, ref missing, ref missing, ref missing);            }
问题三:
在我关闭word的时候,怎样做可以不保存退出呢?不让弹出是否保存对话框,直接退出;我用了个事件,到是可以实现,但是关闭后word程序出现错误,不能正常退出,不知道为什么?
 oWord.DocumentBeforeClose +=
                new Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(
                oWord_DocumentBeforeClose);
private void oWord_DocumentBeforeClose(Word.Document doc, ref bool Cancel)
        {
            object SaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
            object tmissing = Type.Missing;
            oWord.ActiveDocument.Close(ref SaveChanges, ref tmissing, ref tmissing);        } 请大家帮帮忙吧!谢谢

解决方案 »

  1.   

    object missing = System.Reflection.Missing.Value;
                    if (App == null)
                        App = new Microsoft.Office.Interop.Word.ApplicationClass();
                    App.Visible = true;
                    object oTemplate = DotPath.Trim();
                    doc = App.Documents.Add(ref oTemplate, ref missing, ref missing, ref missing);
                   // doc.Activate();
                   
                    Microsoft.Office.Interop.Word.Books bms = doc.Books;
                                  
                    foreach (Microsoft.Office.Interop.Word.Book bm in bms)
                    {
                         bm.Select();
                        
                         bm.Range.Text = dr[bm.Name].ToString();                                
                    }
                           
                                   
                    //关闭文档而不保存
                    object SaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
                    missing = System.Reflection.Missing.Value;
                   // doc.Path = @"E:\我的文档\Visual Studio 2005\Projects\CensusMis\CensusMis\bin\Debug\"+dr["住户姓名"]+".doc";
                    exPath =(object)( exPath.ToString()+@"\" + dr["住户姓名"] + ".doc");
                    doc.SaveAs(ref exPath, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing);
                     doc.Close(ref SaveChanges, ref missing, ref missing);
                     App.Quit(ref SaveChanges, ref missing, ref missing);
                     App = null;