如何在C#4.0中使用Microsoft.Office.Interop.Word.StoryRange获取特定文本框的文本? [英] How to get text of particular text box by using Microsoft.Office.Interop.Word.StoryRange in C#4.0?

查看:298
本文介绍了如何在C#4.0中使用Microsoft.Office.Interop.Word.StoryRange获取特定文本框的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C#应用​​程序与Word文档的交互使用Microsoft.Office.Interop.Word。我的Word应用程序具有常规段落以及文本框中的文本范围。因此,我可以轻松访问特定段落并通过以下方式突出显示...



  int  start = wordDoc.Paragraphs [st_para] .Range.Start; 
int end = wordDoc.Paragraphs [ed_pa​​ra] .Range.End;
Microsoft.Office.Interop.Word.Range r = wordDoc.Range(start,end);
r.Select();





但是现在我想对不属于它的文本做同样的事情Word Document.for的主体,我使用Microsoft.Office.Interop.Word.StoryRange,方式如下:



  int  start = wordDoc.StoryRanges ....(这里我想给出像段落一样的范围)
int end = wordDoc.StoryRanges ......(这里我想给出像段落一样的范围)

Microsoft.Office.Interop.Word.StoryRanges s = wordDoc.StoryRanges;
Microsoft.Office.Interop.Word.Range r = s [WdStoryType.wdTextFrameStory];
// r.SetRange(start,end);
r.Select ();

while ((r = r.NextStoryRange)!= null
{
MessageBox.Show( text: + r.Text);
r.Select();
}





在上面的代码中,逐个迭代文本的所有范围。但我想只得到特定的通过开始和结束变量的文本框值。

请指导我解决这个问题...



预先感谢All,

P.SARAVANAN。

解决方案

我想阅读文档模板(.dot)并导出为msword(doc / docx)文件



1.我想更新复选框字段(true / false)并更新文本框中的值

2.想要更改下拉列表价值

3.更换形状。



我使用了aspose.words,它对我来说很合适,可以做上述步骤。但它更昂贵。所以客户想要免费的lib。

我从msoffice / dotnet尝试了同样的事情,但它提出了很多问题并且无法更新文本字段。



给予RPC服务器不可用,任何帮助都非常感激。



谢谢,

哈哈

hajaworld @ yahoo。 co.in

My C# Application interaction with Word Document using Microsoft.Office.Interop.Word. My Word Application having regular paragraph and also the range of the text in text box.So, I have easily accessed the particular paragraph and highlighted by the following way...

int start = wordDoc.Paragraphs[st_para].Range.Start;
int end = wordDoc.Paragraphs[ed_para].Range.End;
Microsoft.Office.Interop.Word.Range r = wordDoc.Range(start, end);
r.Select();



But now i want to do the same thing for the text that are not part of the main body of the Word Document.for that i am using Microsoft.Office.Interop.Word.StoryRange in the following way:

int start = wordDoc.StoryRanges....(Here i want to give the range like     paragraph)
         int end = wordDoc.StoryRanges......(Here i want to give the range like     paragraph)

         Microsoft.Office.Interop.Word.StoryRanges s = wordDoc.StoryRanges;
         Microsoft.Office.Interop.Word.Range r = s[WdStoryType.wdTextFrameStory];
         //r.SetRange(start, end);
         r.Select();

         while ((r = r.NextStoryRange) != null)
         {
             MessageBox.Show("text:"+r.Text);
             r.Select();
         }      



In the Above code iterate all the range of the text one bye one.But i want to get only particular text box value through start and end variable.
Please guide me to get of this issue...

Advance Thanks to All,
P.SARAVANAN.

解决方案

I wanted to read document template(.dot)and export as msword( doc/docx) file

1. i wanted to update the checkbox field(true/false) and update the value in the textbox
2. wants to change the dropdown value
3. replace the shapes.

I used aspose.words and it is working fine for me for doing above steps. but it s costlier. so client wants free lib.
I tried the same things word interop from msoffice/dotnet but it is giving lot of issue & not able update the textfield.

giving RPC server is not available, any help really appreciated.

Thanks,
Haja
hajaworld@yahoo.co.in


这篇关于如何在C#4.0中使用Microsoft.Office.Interop.Word.StoryRange获取特定文本框的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆