【问题标题】:LibreOffice API/UNO: How to horizontal right-align text in table cell in writerLibreOffice API/UNO:如何在编写器的表格单元格中水平右对齐文本
【发布时间】:2020-01-28 14:16:04
【问题描述】:

我正在使用 C++ 从另一个应用程序控制 LibreOffice/OpenOffice,但如果您也知道 java-bridge,我想您可以帮助我。所以基本上我想加载一个文档(作品),设置一个单元格的文本(作品)并将一个表格单元格设置为水平右对齐(我不知道该怎么做):

我愿意:

// Load Document
Reference <XInterface> rDoc = myLoader->loadComponentFromURL(...); 

// Get Table
Reference <XTextTablesSupplier> rTablesSuppl(rDocument, UNO_QUERY);
Any any = rTablesSuppl->getTextTables()->getByName("Table1");
Reference<XTextTable> rTable(any, UNO_QUERY);

// Set Text in cell
Reference<XCellRange> rRange (rTable, UNO_QUERY);
Reference<XCell> rCell = rRange->getCellByPosition(x, y);
Reference<XTextRange> rTextRange(rCell, UNO_QUERY);
rTextRange->setString("MyNewText");

// Align "MyNewText" right
????

知道如何继续吗?

【问题讨论】:

    标签: api libreoffice openoffice.org uno libreoffice-basic


    【解决方案1】:

    警告...虽然我有使用 C++ 的经验,但我使用 Java 进行 LO API 编程,因此以下内容可能有点偏离。您可能需要稍作调整才能让事情顺利进行。

    在 Java 中并使用单元格名称来获取单元格,我将单元格中的文本右对齐,如下所示:

    XCell xCell = xTextTable.getCellByName(cellname);
    XText xText = UnoRuntime.queryInterface(XText.class, xCell);
    XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xText.getStart());
    xPropertySet.setPropertyValue("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT);
    

    在 C++ 中并使用单元格位置来获取单元格,我认为粗略的翻译是:

    Reference<XCell> rCell = rRange->getCellByPosition(x, y);
    Reference<XText> rText(rCell, UNO_QUERY);
    Reference< XPropertySet > xPropSet( rText->getStart(), UNO_QUERY );
    xPropSet->getPropertyValue("ParaAdjust") >>= com::sun::star::style::ParagraphAdjust.RIGHT;
    

    鉴于您已经拥有的东西,您似乎可以将您的 ???? 替换为以下内容:

    Reference< XPropertySet > xPropSet( rTextRange, UNO_QUERY );
    xPropSet->getPropertyValue("ParaAdjust") >>= com::sun::star::style::ParagraphAdjust.RIGHT;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 2015-01-03
      • 1970-01-01
      • 2014-09-20
      相关资源
      最近更新 更多