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

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

问题描述

我找不到在我的 Java 程序中使用 XWPFDocument (Apache POI) 在 Docx 中制作 RTL 段落的方法.这是我生成 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"));

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

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