如何使用 Range 对象读取 VB.net 中的 Word (*.doc) 文件中复选框的值?
如何使用范围对象读取 VB.net 中的单词 (*.doc) 文件中复选框的值?
这就是我到目前为止所拥有的:
Dim app As New Word.Application
Dim doc As Document
doc = app.Documents.Open("C:\myDoc.doc")
dim chkBox as Bookmark
chkBox = doc.Bookmarks("MyCheckbox")
Dim rng as Range
rng = chkBox.Range
其中“MyCheckbox”是word文档中复选框的书签。
How do I read the value of a checkbox in a word (*.doc) file in VB.net using a range object?
This is what I have so far:
Dim app As New Word.Application
Dim doc As Document
doc = app.Documents.Open("C:\myDoc.doc")
dim chkBox as Bookmark
chkBox = doc.Bookmarks("MyCheckbox")
Dim rng as Range
rng = chkBox.Range
where "MyCheckbox" is the bookmark of the checkbox in the word document.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不使用复选框本身的名称读取复选框的值有什么特殊原因吗?
如果书签定义的范围包含复选框,则根据复选框的插入方式,可以在
InlineShapes
集合(如果复选框与文本内联插入)或>Shapes
集合(如果作为浮动对象插入。)然后,您需要遍历 Shapes 或 InlineShapes 集合来查找相关复选框。
迭代 InlineShapes 集合中的控件
这应该会让您更接近,但如果复选框的名称是可预测的,则最好直接按名称对其进行寻址。
Any particular reason you're not reading the value of the checkbox using the name of the checkbox itself?
If the range defined by your bookmark contains a checkbox, then, depending upon how the checkbox is inserted, it will be found in either the
InlineShapes
collection (if checkbox inserted inline with the text) or theShapes
collection (if inserted as a floating object.)You would then need to iterate through the collection of Shapes or InlineShapes looking for the checkbox in question.
Iterating through controls in InlineShapes collection
This ought to get you closer, but if the name of the checkbox is predictable, it is better to address it directly by name.