【问题标题】:openoffice: duplicating rows of a table in writeropenoffice:在 writer 中复制表的行
【发布时间】:2010-12-27 19:01:57
【问题描述】:

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

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

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

【问题讨论】:

    标签: python templates openoffice.org openoffice-writer odt


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多