word分页问题

alieneagle 2011-05-17 04:16:49
执行代码后,第1页与第2页之间插入分页符无效,之后的的分页符就没事,不知怎么回事,大家帮忙吧:
void test()
{
//开启word对象
object Nothing = System.Type.Missing;
object format = System.Type.Missing;

Word.Application wordApp = new Word.ApplicationClass();

string rootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
if(rootPath.EndsWith("\\"))
{
rootPath = rootPath.Substring(0, rootPath.Length - 1);
}
string wordFileName = DateTime.Now.ToString("yyyyMMddhhmmssffff") + ".doc";
object srcFileName = rootPath + "\\temp\\" + wordFileName;

Word.Document wordDoc2 = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

wordDoc2.Paragraphs.Last.Range.InsertFile(@"D:\Projects\SZPJXXB\temp\201105131120285312\jbszdy.html", ref Nothing, ref Nothing, ref Nothing, ref Nothing);

//光标移动到文档最后一行。
wordApp.Selection.WholeStory();
object MoveUnit = Word.WdUnits.wdStory;
object MoveExtend = Type.Missing;
wordApp.Selection.EndKey(ref MoveUnit, ref MoveExtend);


//插入分页符
object BreakType = Word.WdBreakType.wdPageBreak;
wordApp.Selection.InsertBreak(ref BreakType);

wordDoc2.Paragraphs.Last.Range.InsertFile(@"D:\Projects\SZPJXXB\temp\201105130236554062\zbxxdy.html", ref Nothing, ref Nothing, ref Nothing, ref Nothing);

wordApp.Selection.EndKey(ref MoveUnit, ref MoveExtend);
wordApp.Selection.InsertBreak(ref BreakType);

wordDoc2.Paragraphs.Last.Range.InsertFile(@"D:\Projects\SZPJXXB\temp\201105131120285312\jbszdy.html", ref Nothing, ref Nothing, ref Nothing, ref Nothing);

wordApp.Selection.EndKey(ref MoveUnit, ref MoveExtend);
wordApp.Selection.InsertBreak(ref BreakType);

wordDoc2.Paragraphs.Last.Range.InsertFile(@"D:\Projects\SZPJXXB\temp\201105130236554062\zbxxdy.html", ref Nothing, ref Nothing, ref Nothing, ref Nothing);

wordDoc2.SaveAs(ref srcFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);


wordDoc2.Close(ref Nothing, ref Nothing, ref Nothing);

if (wordDoc2 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc2);
wordDoc2 = null;
}
//关闭wordApp
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
if (wordApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
wordApp = null;
}
}
...全文
199 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
alieneagle 2011-05-18
  • 打赏
  • 举报
回复
大家帮忙啊
hubo166 2011-05-17
  • 打赏
  • 举报
回复
求同,忘高手指点

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧