openoffice:在writer中复制表的行 [英] openoffice: duplicating rows of a table in writer

查看:106
本文介绍了openoffice:在writer中复制表的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式在openoffice编写器中复制表的行.

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

通过table.Rows.insertByIndex(idx, count)添加行并不难,这会添加空行,并且很容易在该行中添加将DataArray分配给CellRange的文本.这样一来,您就失去了对单元格样式的控制,特别是如果一个单元格中具有不同样式(粗体/斜体)的单词,它们会变平到同一张脸.我需要的是重复一行,以保留单元格/行中每个单词的样式.

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.

这是使用openoffice( http://oootemplate.argolinux.org ).我通过Python的uno界面访问该文档,但是任何语言都可以解释其背后的逻辑.

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.

推荐答案

解决方案是使用控制器的方法.getTrasferable()从ViewCursor获取数据.进而需要您控制视图光标并将其定位在每个单元格中(我无法使ViewCursor跨越多个单元格).获取可转让资产后,请将光标放在目标位置并插入.

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)

这篇关于openoffice:在writer中复制表的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆