Apache的POI autoSizeColumn调整大小不正确 [英] Apache POI autoSizeColumn Resizes Incorrectly

查看:508
本文介绍了Apache的POI autoSizeColumn调整大小不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache POI在Java中创建一个Excel文件。我填写的数据,然后尝试自动调整大小的每一列,但大小永远是错的(我的认为的一致)。前两行始终(?)完全倒塌。当我AUTOSIZE在Excel中的列,它完美的作品。

I'm using Apache POI in java to create an excel file. I fill in the data then try to autosize each column, however the sizes are always wrong (and I think consistent). The first two rows are always(?) completely collapsed. When I autosize the columns in excel, it works perfectly.

正在写入没有空白单元格(我相信),并调整大小是在最后的事我做的。

No blank cells are being written (I believe) and the resizing is the last thing I do.

下面是相关的code:这是一个归结版本没有错误处理等

Here's the relevant code: This is a boiled down version without error handling, etc.

public static synchronized String storeResults(ArrayList<String> resultList, String file) {
    if (resultList == null || resultList.size() == 0) {
        return file;
    }
    FileOutputStream stream = new FileOutputStream(file);

    //Create workbook and result sheet
    XSSFWorkbook book = new XSSFWorkbook();
    Sheet results = book.createSheet("Results");

    //Write results to workbook
    for (int x = 0; x < resultList.size(); x++) {
        String[] items = resultList.get(x).split(PRIM_DELIM);

        Row row = results.createRow(x);
        for (int i = 0; i < items.length; i++) {
            row.createCell(i).setCellValue(items[i]);
        }
    }

    //Auto size all the columns
    for (x = 0; x < results.getRow(0).getPhysicalNumberOfCells(); x++) {
        results.autoSizeColumn(x);
    }

    //Write the book and close the stream
    book.write(stream);
    stream.flush();
    stream.close();

    return file;
}

我知道有几个问题在那里相似,但他们大多只是大小的数据填充之前的情况。而这是不是少数比较复杂/未答复。

I know there are a few questions out there similar, but most of them are simply a case of sizing before filling in the data. And the few that aren't are more complicated/unanswered.

编辑:我试图用几个不同的字体和它没有工作。这是不是太奇怪,因为不管是什么字体要么所有的列应完全坍塌或无应。

I tried using a couple different fonts and it didn't work. Which isn't too surprising, as no matter what the font either all the columns should be completely collapsed or none should be.

此外,因为字体问题来了,我在Windows 7上运行的程序。

Also, because the font issue came up, I'm running the program on Windows 7.

解决:这是一个字体的问题。我发现的唯一的字体是工作衬线。

SOLVED: It was a font issue. The only font that I found that worked was Serif.

推荐答案

只是为了回答我的评论。该行不能正确尺寸因为Java不知道你想使用的此链接应该帮助,如果你想安装新字体为Java,所以你可以使用的东西票友。它也有默认字体列表中了Java知道了。

Just to make an answer out of my comment. The rows couldn't size properly because Java was unaware of the font you were trying to use this link should help if you want to install new fonts into Java so you could use something fancier. It also has the list of default fonts that Java knows.

高兴这帮助和你有你的问题解决了!

Glad this helped and you got your issue solved!

这篇关于Apache的POI autoSizeColumn调整大小不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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