1

我需要在 openoffice writer 中以编程方式复制表的行。

通过添加行并不困难table.Rows.insertByIndex(idx, count),添加空行并且很容易在该行中添加文本分配DataArrayCellRange. 这样做你可以放松对单元格样式的控制,特别是如果一个单元格有不同样式(粗体/斜体)的单词,它们会被压扁到同一张脸。我需要的是以保留单元格/行中每个单词的样式的方式复制一行。

这是使用 openoffice ( http://oootemplate.argolinux.org ) 的 Python 模板系统的最后一步。我通过 Python 中的 uno 接口访问文档,但任何语言都可以解释其背后的逻辑。

4

1 回答 1

5

解决方案是使用控制器的方法 .getTrasferable() 从 ViewCursor 获取数据。这反过来要求您控制视图光标并将其定位在每个单元格中(我无法使 ViewCursor 跨越多个单元格)。一旦你获得了可转移的,你将光标放在目的地并插入。

  desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
  document = desktop.loadComponentFromURL("file://%s/template-debug.odt" % os.getcwd() ,"_blank", 0, ())
  controller=document.getCurrentController()
  table = document.TextTables.getByIndex(0)
  view_cursor=controller.getViewCursor()


  src = table.getCellByName(src_name)
  dst = table.getCellByName(dst_name)

  view_cursor.gotoRange(src.Text, False)
  txt = controller.getTransferable()
  view_cursor.gotoRange(dst.Text, False)

  controller.insertTransferable(txt)
于 2011-01-04T16:54:57.943 回答