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

标签 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 中没有这样的东西。看来每列/行都必须单独调整。有两种方法可以做到这一点:

  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/

相关文章:

javascript - sweet.js 无法返回 #`else`

python - ODS 文件转 JSON

.net - .NET 最好的文字处理组件是什么

c++ - 在附加包含目录中使用预处理器定义

c - 如何编写获取函数运行时间的宏?

macros - Libreoffice 计算 : loop throught cells macro

syntax-highlighting - 在文字处理器中使用语法突出显示的代码

java - ascii 谱中未分配的字符?

syntax - Common Lisp 宏语法关键字 : what do I even call this?

csv - LibreOffice/OpenOffice Calc : VBscript, 将 XLS 工作表导出为 CSV