asp.net里操作word.关于改写模式?(在线等待,菜鸟跪求)

dandan996 2009-12-10 02:51:19
(在代码里启动了改写模式.为什么运行后没效果.依然是普通的插入模式)
private Microsoft.Office.Interop.Word.Application appword = new Microsoft.Office.Interop.Word.Application();
#region ------------生成合同--------------
public void GetWord()
{
try
{
string TemplateFile = @"D:\WorkSpace\text\合同模板.doc";
//生成的具有模板样式的新文件
string FileName = @"D:\WorkSpace\text\" + BookMarkhtbianhao + ".doc";
File.Copy(TemplateFile, FileName);
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object Obj_FileName = FileName;
object Visible = false;
object ReadOnly = false;
object missing = System.Reflection.Missing.Value;
appword.Options.Overtype = true;
//打开文件
doc = appword.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);

foreach (Bookmark bank in doc.Bookmarks)
{
switch (bank.Name)
{
case "BookMarkcgrdlr":
bank.Select();
SelectionInsertText(BookMarkcgrdlr.Trim());
break;

case "BookMarkcgrdw":
bank.Select();
SelectionInsertText(BookMarkcgrdw.Trim());
break;

case "BookMarkcgrfrdb":
bank.Select();
SelectionInsertText(BookMarkcgrfrdb.Trim());
break;

case "BookMarkcgryhang":
bank.Select();
bank.Range.Text = "";
break;

case "BookMarkcgryouzhengbh":
bank.Select();
bank.Range.Text = "";
break;

case "BookMarkcgrzhanghao":
bank.Select();
bank.Range.Text = "";
break;
default:
bank.Select();
bank.Range.Text = "";
break;
}
}
object IsSave = true;
doc.Close(ref IsSave, ref missing, ref missing);
//杀掉进程
killAllProcessDan();
}
catch (Exception ex)
{

}
finally
{
//杀掉进程
killAllProcessDan();
}
}
#endregion
#region -----------------在当前光标位置插入内容----------------
/// <summary>
/// 在当前光标位置插入内容
/// </summary>
/// <param name="text">内容</param>
public void SelectionInsertText(string text)
{
Microsoft.Office.Interop.Word.Selection currentSelection = appword.Selection;

// Store the user's current Overtype selection
bool userOvertype = appword.Options.Overtype;

// Make sure Overtype is turned off.
//if (!appword.Options.Overtype)
//{
// appword.Options.Overtype = true;
//}
appword.Options.Overtype = true;
// Test to see if selection is an insertion point.
if (currentSelection.Type == Microsoft.Office.Interop.Word.WdSelectionType.wdSelectionIP)
{
//currentSelection.TypeText("Inserting at insertion point. ");
currentSelection.TypeText(text);
//currentSelection.TypeParagraph();
}
else
{
if (currentSelection.Type == Microsoft.Office.Interop.Word.WdSelectionType.wdSelectionNormal)
{
// Move to start of selection.
if (appword.Options.ReplaceSelection)
{
object direction = Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseStart;
currentSelection.Collapse(ref direction);
}
//currentSelection.TypeText("Inserting before a text block. ");
currentSelection.TypeText(text);
//currentSelection.TypeParagraph();
}
else
{
// Do nothing.
}
}

// Restore the user's Overtype selection
appword.Options.Overtype = true;
}
...全文
70 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mbh0210 2009-12-10
  • 打赏
  • 举报
回复
估计是模板替换之类的,检查代码吧
Lovely_baby 2009-12-10
  • 打赏
  • 举报
回复
不知道 楼主要干么??
设断点跟踪一下~~

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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