本文介绍了Apache的POI Excel中 - 如何配置列扩大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Apache POI API 生成 Excel的小号preadsheet 来输出一些数据。

I am using Apache POI API to generate excel spreadsheet to output some data.

我现在面临的问题是创建并打开在S preadsheet时,列不扩大,使一些长期文字,如日期格式的文本没有显示在乍一看起来。

The problem I am facing is when the spreadsheet is created and opened, columns are not expanded so that some long text like Date formatted text is not showing up on first glance.

我可以双击在Excel列边框扩展或拖动边界,调整列宽,但有可能是20多列,也没有办法,我想那我手动打开在S $ P每次做$ padsheet:(

I could just double click the column border in excel to expand or drag the border to adjust the column width but there could be 20+ columns and there is no way I want to do that manually every time I open the spreadsheet :(

我发现了(尽管可能是错误的方法) groupRow() setColumnGroupCollapsed()也许能够这样的伎俩,但没有运气。也许我使用它错了。

I found out (though could be wrong method) groupRow() and setColumnGroupCollapsed() might be able to do the trick but no luck. Maybe I'm using it in wrong way.

样品code段

        Workbook wb = new HSSFWorkbook();
        CreationHelper createHelper = wb.getCreationHelper();
        //create sheet
        Sheet sheet = wb.createSheet("masatoSheet");

        //not really working yet.... :(
        //set group for expand/collapse
        //sheet.groupRow(0, 10); //just random fromRow toRow argument values...
        //sheet.setColumnGroupCollapsed(0, true);

        //create row
        Row row = sheet.createRow((short)0);
        //put a cell in the row and store long text data
        row.createCell(0).setCellValue("Loooooooong text not to show up first");

当这个s是创建preadsheet的Looooooong文字不露面先串是在单元格中,但由于该列不扩大只是Loooooooo被显示出来。

我如何配置它,这样当我打开我的小号preadsheet,列已经展开??​​?

How can I configure it so that when I open my spreadsheet, the column is already expanded???

推荐答案

之后您已经添加在你的表来自动调整列所有的数据到表,你可以调用autoSizeColumn(columnNumber)正确的尺寸

After you have added all your data to the sheet, you can call autoSizeColumn(columnNumber) on your sheet to autofit the columns to the proper size

下面是对 API

看到这个职位更多参考
Problem在Excel单元格大小配合到内容的大小时,使用Apache POI

See this post for more referenceProblem in fitting the excel cell size to the size of the content when using apache poi

这篇关于Apache的POI Excel中 - 如何配置列扩大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 12:19