首页 文章

openoffice:在writer中复制表的行

提问于
浏览
1

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

通过 table.Rows.insertByIndex(idx, count) 添加行并不困难,这会添加空行,并且可以轻松地在该行中添加文本,将 DataArray 分配给 CellRange . 通过这种方式,您可以放松对单元格样式的控制,特别是如果单元格具有不同样式(粗体/斜体)的单词,则会将其展平为同一个面 . 我需要的是以保留单元格/行中每个单词的样式的方式复制行 .

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

1 回答

  • 5

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

    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)
    

相关问题