我想要一个可以逐段显示单词文档的代码 [英] I want a code which will display the word document paragraph by paragraph

查看:111
本文介绍了我想要一个可以逐段显示单词文档的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我试图在文本框中逐段显示Word文档的内容.我尝试了一个代码,它一次显示所有内容并显示最后一段.但我想手动中断显示内容.
例如,如果我单击下一个按钮,则应显示下一个段落,如果我单击上一个按钮,则应显示上一个段落.
请给我建议一个代码.
在此先感谢

电子邮件ID:已删除

Hi,
Am trying to display the contents of word document paragraph by paragraph in the textbox. i tried a code and it is displaying everything at a time and displaying the last paragraph. But i want to display the contents with manual interruption.
For example if i click on next button it should display the next paragraph and if i click on previous button it should display the previous paragraph.
Please suggest me a code.
Thanks in advance

Email ID: removed

推荐答案

在加载Word文档时,您可能应该将文档分解为List< string>列表中的每个项目都包含一个段落.然后,您只需浏览列表中的项目并显示它们即可.

更新:
When you load your word document, you should probably break document up into a List<string> where each item in the list contains a single paragraph. Then all you have to do is navigate through the items in the List and show them.

Update:
Dim currentIndex As Int
Dim list As New List(Of String)

currentIndex = 0

For Each p In currentDocument.Paragraphs
   list.Add(p.range.text)
Next p

TextBox.Text = list[currentIndex]

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
   currentIndex = currentIndex + 1
   TextBox.Text = list[currentIndex]
End Sub


由于我不再进行任何VB.Net开发,因此此代码段中可能存在一些语法错误,但是我认为这可以为您带来灵感.您还必须确保先进行验证,以确保诸如currentIndex之类的东西在有效范围内,然后再尝试应用它们.


There are probably some syntax errors in this snippet as I don''t do any VB.Net development anymore, but I think this will give you the idea. You''ll also have to make sure to validate to make sure that things like the currentIndex and such are within a valid range before trying to apply them.


这篇关于我想要一个可以逐段显示单词文档的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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