简体   繁体   English

LibreOffice API/UNO:如何在 writer 中的表格单元格中水平右对齐文本

[英]LibreOffice API/UNO: How to horizontal right-align text in table cell in writer

I'm using C++ to control LibreOffice/OpenOffice from another application, but I guess you can help me if you know the java-bridge as well.我正在使用 C++ 从另一个应用程序控制 LibreOffice/OpenOffice,但我想如果你也知道 java-bridge,你可以帮助我。 So basically I want to load a document (works), set the text of a cell (works) and set a table-cell to horizontal align right (which I got no idea how to do it):所以基本上我想加载一个文档(作品),设置单元格的文本(作品)并将表格单元格设置为水平右对齐(我不知道该怎么做):

I do:我愿意:

// 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
????

Any idea how to continue?知道如何继续吗?

Caveat... While I have experience with C++, I use Java for LO API programming, so the following may be a bit off.警告...虽然我有使用 C++ 的经验,但我使用 Java 进行 LO API 编程,因此以下内容可能有点不对。 You'll probably have to tweak a bit to get things going.你可能需要稍微调整一下才能让事情顺利进行。

In Java and using the cell name to get the cell, I right-justified text in a cell like this:在 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);

In C++ and using the cell position to get the cell, I'm thinking that a rough translation would be:在 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;

Given what you've already got, it looks like you might be able to just replace your ????鉴于您已经拥有的,看起来您可以更换您的???? with something like this:像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM