从右到左(RTL)的文本XWPFDocument(Apache的POI) [英] Right to Left (RTL) text in XWPFDocument (Apache POI)

查看:394
本文介绍了从右到左(RTL)的文本XWPFDocument(Apache的POI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到一种方法,使在使用DOCX XWPFDocument(Apache的POI)在我的Java程序中的RTL段落。这里是我的code产生的XWPFDocument。

I could not find a way to make a RTL paragraph in Docx using XWPFDocument (Apache POI) in my Java program. Here's my code that generates the XWPFDocument.

    XWPFParagraph title = document.createParagraph();
    title.setAlignment(ParagraphAlignment.CENTER);
    title.setVerticalAlignment(TextAlignment.CENTER);
    title.setWordWrap(true);
    XWPFRun titleRun = title.createRun();
    titleRun.setText(reportDesign.getName());

    XWPFTable s = document.createTable(resultList.size()+1, columnList.size());
    // declare a row object reference
    XWPFTableRow r = s.getRow(0);
    // declare a cell object reference
    XWPFTableCell c = null;
    // create columnList.size() cells (0-(columnList.size()-1))
    for (int cellnum = 0; cellnum < columnList.size(); cellnum++) {
        c = r.getCell(cellnum);
        c.setColor("c9c9c9");
        c.setVerticalAlignment(XWPFVertAlign.CENTER);
        c.setText(columnList.get(cellnum).getColumnHeader());
    }
    // create a sheet with resultList.size() rows (1-resultList.size())
    for (int rownum = 0; rownum < resultList.size(); rownum++) {
        // create a row
        r = s.getRow(rownum+1);

        // create columnList.size() cells (0-(columnList.size()-1))
        for (int cellnum = 0; cellnum < columnList.size(); cellnum++) {
            c = r.getCell(cellnum);
            Object value = resultList.get(rownum).get(columnList.get(cellnum).getColumnKey());
            if (value != null) {
                c.setText(value.toString());
            } else {
                c.setText("");
            }
        }
    }

请你帮我吗?有没有为获得这一功能延长POI(或类似的解决方案),更合理的方式?

Would you please help me? Is there a logical way to extend POI (or similar solution) for gaining this feature?

推荐答案

一个解决办法,我发现到目前为止使用模板文件。

A workaround that I found till now is using a template document.

使用这种方法,你让一个空文件,在其正常的风格,被配置成RTL。这样一来,一切都在文档中会RTL。

Using this method, you make an empty document that "Normal" style in it, is configured to be RTL. This way, everything in your document will be RTL.

XWPFDocument document = new XWPFDocument(AbstractWordView.class.getClassLoader().getResourceAsStream("empty.docx"));

这篇关于从右到左(RTL)的文本XWPFDocument(Apache的POI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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