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;
}
}
...全文
253 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
alieneagle 2011-05-18
  • 打赏
  • 举报
回复
大家帮忙啊
hubo166 2011-05-17
  • 打赏
  • 举报
回复
求同,忘高手指点
内容概要:本文围绕“面向高精度电流控制的PMSM多参数PSO辨识模型研究”,系统阐述了基于Simulink的永磁同步电机(PMSM)多参数辨识方法,重点采用粒子群优化算法(PSO)实现对电机关键内部参数的高精度辨识。研究构建了完整的PMSM控制系统仿真模型,结合智能优化算法,解决了传统参数辨识中精度低、收敛慢的问题,有效提升了电流环控制的动态性能与稳态精度。该方法特别适用于对控制精度和响应速度要求较高的工业应用场景,如高性能伺服系统、电动汽车驱动系统等,具有较强的工程实用价值和科研参考意义。文中提供了完整的Simulink仿真模型与配套代码,确保了研究内容的可复现性和实践操作性。; 适合人群:具备电机控制、自动化或电气工程等相关专业背景,熟悉MATLAB/Simulink仿真环境,从事电机驱动系统研发、控制算法设计或相关领域科研工作的工程师及研究生,尤其适合工作1-5年、希望深入理解先进参数辨识技术的研发人员。; 使用场景及目标:①开展高精度PMSM控制系统的设计与参数辨识研究;②学习并掌握PSO等智能优化算法在电机系统参数辨识中的具体实现与调优技巧;③完成学术论文复现、科研项目验证、毕业设计或工程原型开发,提升对现代电机控制核心技术的理解与应用能力。; 阅读建议:建议读者结合提供的Simulink模型与源代码进行动手实践,按照文档逻辑逐步搭建与调试仿真系统,重点关注PSO算法与电机模型的交互机制、目标函数设计及参数收敛过程,通过对比不同工况下的辨识结果,深入理解算法性能与控制精度之间的内在联系。

111,129

社区成员

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

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

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