LibreOffice API/UNO:如何在writer的表格单元中水平右对齐文本 [英] LibreOffice API/UNO: How to horizontal right-align text in table cell in writer

查看:72
本文介绍了LibreOffice API/UNO:如何在writer的表格单元中水平右对齐文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 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):

我愿意:

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

推荐答案

注意事项...虽然我有C ++的经验,但是我使用Java进行LO API编程,因此以下内容可能有点过时.您可能需要进行一些调整才能使事情进展.

在Java中,使用单元名称获取单元,我在像这样的单元中右对齐文本:

In Java and using the cell name to get the cell, I right-justified text in a cell like this:

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 ++中,使用单元格位置获取单元格,我认为粗略的翻译是:

In C++ and using the cell position to get the cell, I'm thinking that a rough translation would be:

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;

这篇关于LibreOffice API/UNO:如何在writer的表格单元中水平右对齐文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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