gpt4 book ai didi

macros - LibreOffice 4.1 编写器 : macro to adjust column widths in tables

转载 作者:行者123 更新时间:2023-12-02 11:49:38 28 4
gpt4 key购买 nike

我正在开发一些适用于表格的 LibreOffice 宏,特别是将每列和行的宽度和高度设置为 0.85 厘米(0.335 英寸)。

在 MS Office 中,这很简单,只需选择表格并在宏中包含:

Selection.Rows.Height = CentimetersToPoints(0.85)
Selection.Columns.PreferredWidth = CentimetersToPoints(0.85)

LibreOffice 4.1 中没有这样的东西。看来每列/行都必须单独调整。有两种方法可以做到这一点:

  1. 迭代所有列/行并调整每个列/行

  2. 将第一列/行调整为仔细计算的宽度/高度,然后调用均匀分布列/行

为了了解代码,我尝试使用宏记录器并浏览了表|表属性并进行了反复尝试,直到表看起来不错,但我所做的大部分内容都没有记录在宏中。

有人做过这样的事吗?

最佳答案

这是我所能得到的:

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

注意到的主要问题:

  1. 无法通过 ThisComponent.CurrentSelection 检索要修改的实际表,因此硬编码到索引 0 处的表

  2. 对表格的任何更改似乎都没有反射(reflect)在文档中,并且没有明显的方法来重新渲染或刷新似乎现在正在工作!但仍在寻找调用函数来均匀分布列的方法

  3. columns.getByIndex 始终返回 NULL!并且没有关于如何在 Basic 中使用列枚举类的文档

根据本次调查,建议反对尝试使用 LibreOffice 4.1 Writer Basic 宏进行任何富有成效的操作。

关于macros - LibreOffice 4.1 编写器 : macro to adjust column widths in tables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19605183/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com