从Word中删除不需要的分节符?

时间:2011-09-22 10:21:11

标签: c# .net winforms com ms-word

我正在尝试在MS Word中创建一个信封。以下代码将创建一个信封,但我在该页面的顶部显示“分节符(下一页)”。我想删除它。

 oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                oDoc.Activate();
                object ExtractAddress = false;
                object Address = "Address" ;
                object AutoText = "AutoText" ;
                object OmitReturnAddress = false;
                object ReturnAddress = "ReturnAddress" ;
                object ReturnAutoText = "ReturnAutoText";
                object PrintBarCode = false;
                object PrintFIMA = false;
                object Size = "E65";
                object Height = 110;
                object Width = 220;
                object FeedSource = true;
                object AddressFromLeft = 2;
                object AddressFromTop = 2;
                object ReturnAddressFromLeft = 2;
                object ReturnAddressFromTop = 2;
                object DefaultFaceUp = true;
                object DefaultOrientation = Microsoft.Office.Interop.Word.WdEnvelopeOrientation.wdCenterPortrait;
                object PrintEPostage = false;
                object Vertical = false;
                object RecipientNamefromLeft = Missing.Value;
                object RecipientNamefromTop = Missing.Value;
                object RecipientPostalfromLeft = Missing.Value;
                object RecipientPostalfromTop = Missing.Value;
                object SenderNamefromLeft = Missing.Value;
                object SenderNamefromTop = Missing.Value;
                object SenderPostalfromLeft = Missing.Value;
                object SenderPostalfromTop = Missing.Value;
                oDoc.Envelope.Insert(ref ExtractAddress, ref Address, ref AutoText, 
                    ref OmitReturnAddress, ref ReturnAddress, ref  ReturnAutoText, 
                    ref  PrintBarCode, ref  PrintFIMA, ref  Size, ref  Height, 
                    ref  Width, ref  FeedSource, ref  AddressFromLeft, ref  AddressFromTop, 
                    ref  ReturnAddressFromLeft, ref  ReturnAddressFromTop, ref  DefaultFaceUp,
                    ref  DefaultOrientation, ref  PrintEPostage, ref  Vertical, 
                    ref  RecipientNamefromLeft, ref  RecipientNamefromTop, 
                    ref  RecipientPostalfromLeft, ref  RecipientPostalfromTop, 
                    ref  SenderNamefromLeft, ref  SenderNamefromTop, ref  SenderPostalfromLeft,  
                    ref  SenderPostalfromTop);

1 个答案:

答案 0 :(得分:1)

在使用Word的信封功能后,我注意到这不是一个编程问题(虽然你让它看起来像一个)。如果您手动将信封插入文档,您还将获得一个分节符,它将信封部分与文档的其余部分分开,因为两者都有不同的纸张大小。我没有找到一个简单的方法来轻松摆脱那个部分休息,同时仍然保持信封大小完整,所以这是我的建议,以实现这一点:

  • 不要使用Word的“信封”功能
  • 手动调整纸张尺寸和边距(在Word中,使用菜单/色带),并将地址和返回地址放在您希望的位置
  • 使用宏录制器录制VBA命令以执行此操作
  • 将VBA代码移植到C#