openoffice:在writer中复制表的行

发布于 2024-10-09 08:10:17 字数 457 浏览 0 评论 0原文

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

通过 table.Rows.insertByIndex(idx, count) 添加行并不困难,这会添加空行,并且很容易在该行中添加文本,将 DataArray 分配给 <代码>单元格范围。通过这种方式,您将失去对单元格样式的控制,特别是如果单元格具有不同样式(粗体/斜体)的单词,它们会被展平为同一张脸。我需要的是以保留单元格/行中每个单词的样式的方式复制一行。

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

I need to programmatically duplicate rows of a Table in openoffice writer.

It's not difficult to add rows via table.Rows.insertByIndex(idx, count), that adds empty rows and it's easy to add text in that row assigning DataArray to the CellRange. Doing this way you loose control on the style of the cells and specifically if a cell has words with different style (bold/italic) they get flattened to the same face. What I need is to duplicate a row in a way that preserves the style of each word in the cell/row.

This is the last step of a Python template system that uses openoffice (http://oootemplate.argolinux.org). I access the document via uno interface in Python but any language would do to explain the logic behind it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰火雁神 2024-10-16 08:10:17

解决方案是使用控制器的方法 .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)

The solution is to use controller's method .getTrasferable() to get data from the ViewCursor. that in turn requires that you control your view cursor and position it in every single cell (I was not able to make the ViewCursor span multiple cells). Once you have acquired the transferable you place the cursor in the destination and insert.

  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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文