Macros libreoffice4.1 Writer:用于调整表中列宽的宏
我正在处理一些用于表格的LibreOffice宏,特别是将每列和每行的宽度和高度设置为0.85厘米(0.335英寸) 在MS Office中,这很简单,只需选择表格并在宏中选择:Macros libreoffice4.1 Writer:用于调整表中列宽的宏,macros,libreoffice,word-processor,Macros,Libreoffice,Word Processor,我正在处理一些用于表格的LibreOffice宏,特别是将每列和每行的宽度和高度设置为0.85厘米(0.335英寸) 在MS Office中,这很简单,只需选择表格并在宏中选择: Selection.Rows.Height = CentimetersToPoints(0.85) Selection.Columns.PreferredWidth = CentimetersToPoints(0.85) LibreOffice 4.1中没有类似的内容。似乎每个列/行都必须单独调整。有两种方法可以做到
Selection.Rows.Height = CentimetersToPoints(0.85)
Selection.Columns.PreferredWidth = CentimetersToPoints(0.85)
LibreOffice 4.1中没有类似的内容。似乎每个列/行都必须单独调整。有两种方法可以做到这一点:
有人做过这样的事吗?这里是我能得到的:
sub Testing
dim tables as object
dim table as object
dim columns as object
dim column as object
dim index as integer
tables = ThisComponent.TextTables
if tables.Count > 0 then
table = tables.getByIndex(0)
columns = table.columns
table.Width = 850 * columns.Count '850 == 0.85 cm
for index = 0 to columns.Count - 1
column = columns.getByIndex(index)
'column is always NULL
'column.Width = 850
next
end if
end sub
注意到的主要问题:
ThisComponent.CurrentSelection
检索要修改的实际表,因此只能硬编码到索引0处的表中columns.getByIndex
始终返回NULL
!,并且没有关于如何在Basic中使用列枚举类的文档根据这项调查,我建议不要试图用LibreOffice 4.1 Writer Basic宏做任何有成效的事情。最后我找到了解决这个问题的办法 但仍然不知道该单元的位置属性是什么
Sub Main
dim tables as object
dim table as object
dim tid as integer
dim sep()
tables = ThisComponent.TextTables
for tid = 0 to tables.count - 1
table = tables(tid)
table.Width = 26000
sep = table.TableColumnSeparators
sep(0).Position = 1600
table.TableColumnSeparators = sep
next
End Sub
我试图通过使用来计算适当的相对值来设置每行的位置,从而将表中所有单元格的宽度设置为某个值。有必要使用相对值,因为,正如解释所示: 表格的实际宽度取决于环境(页面样式和表格位置的文本列数、对齐方式以及左右边距)。因此,表列分隔符不包含列宽的度量值。这些值与TextTable::TableColumnRelativeSum属性的值相关 所以我得到了这段代码,它运行时没有错误,而且似乎可以工作。但在某些表上(并非所有行都相同的“复杂”表),某些分隔符不会移动
Sub Main
dim tables as object
dim table as object
dim tid as integer
' Get table
tables = ThisComponent.TextTables
table = tables.getByName("Table5")
tableWidthRelative = table.TableColumnRelativeSum
tableWidthIn = 5.5
columnWidthIn = 0.89
columnWidthRelative = columnWidthIn / tableWidthIn * tableWidthRelative
' Get rows
rows = table.getRows()
for i = 0 to (rows.Count() - 1)
row = rows.getByIndex(i)
' Seps
seps = row.TableColumnSeparators
' TableColumnSeparators is a Sequence, which does not support the Count method. You must use UBound() to get its length.
numSeps = UBound(seps)
for s = 0 to numSeps
sep = seps(s)
sep.Position = columnWidthRelative * (s+1)
seps(s) = sep
next
row.TableColumnSeparators = seps
table.Rows(i) = row
next
end sub
我之所以把它放在这里,是因为想弄明白这件事真是一团糟,也许有一天这会对别人有所帮助
最后,最有效的方法是使用Bash脚本,使用xdool
将键盘输入发送到LibreOffice
LibreOffice网站提供了更多详细信息。感谢您的坚持不懈!转换为1个单位=10µm=0.01 mm=0.001 cm,因此:26000个单位=260 mm=26 cm,1600个单位=16 mm=1.6 cm对于设置第一列的宽度很好。