ruby - Win32ole - Word 在错误的位置插入书签页码
问题描述
我正在使用 ruby 自动创建一些 word 文档,并且遇到了一个奇怪的问题,在表格中,插入引用书签的页码会将其插入错误的位置。
这是一些重现该问题的示例代码。
require 'win32ole'
#setup new document
word = WIN32OLE.new('Word.Application')
word.Visible = true
word.Documents.Add('Normal.dotm')
doc = word.ActiveDocument
#create new table and merge cells
doc.Tables.Add(word.Selection.Range, 2, 2)
table_number = 1
doc.Tables(table_number).Borders.Enable = true
start_cell = doc.Tables(table_number).Cell(1,1)
end_cell = doc.Tables(table_number).Cell(1,2)
start_cell.Merge('MergeTo' => end_cell)
#putting some dummy text in
doc.Tables(table_number).Cell(1,1).Range.Text = 'Example Text'
doc.Tables(table_number).Cell(2,1).Range.Text = 'Filler'
#creating a bookmark
doc.Tables(table_number).Cell(1,1).Select
current_BM = "BM"
doc.Bookmarks.Add(current_BM, word.Selection)
#Attempting to insert the bookmark in the 2,2 cell
doc.Tables(table_number).Cell(2,2).Select
word.selection.InsertCrossReference("Bookmark",7,current_BM,true)
您可能希望将书签插入到 2,2 单元格中,但它会将其插入到 2,1 单元格的开头。
关于如何让它插入正确位置的任何想法?任何帮助将不胜感激。
解决方案
推荐阅读
- forms - 当 API 源生成表单控制选项时,浮动标签不起作用
- pandas - 使用新 pyspark.pandas 的正确方法?
- python - 如何使用python从交易视图中的指标获取价值
- python - Elasticsearch - 计算索引中所有文本中的单词出现次数
- sql - SNOWFLAKE 数据库中关于主键错误的合并语句
- python - Bandit B404 子流程导入的安全问题?
- python - 如何在numpy中矩阵乘以3个矩阵?
- android - 如何转到另一个选项卡,但保留上一个选项卡
- javascript - 为什么 Javascript 的 FileReader 它不维护 .csv 扩展名
- image-segmentation - 使用傅里叶变换或霍夫变换确定二值图像线的对齐方式?