Autowidth is not working for merged columns

后端 未结 1 1715
自闭症患者
自闭症患者 2021-01-18 10:40
{
row=sheet.createRow(0);
cell=row.createCell(0);
cell.setCellValue(\"header\");
cell=row.createCell(1);
sheet.addMergedRegion(new CellRangeAddress(0,0,0,1));
row=sh         


        
相关标签:
1条回答
  • 2021-01-18 10:47

    I've spotted your problem, it's this line:

    sheet.autoSizeColumn(0);
    

    From the javadocs on autoSizeColumn(int) we see this key bit of information:

    Default is to ignore merged cells.

    You need to switch to instead call autoSizeColumn(int,boolean), and pass in a true value. This will tell POI to take account of merged cells during the sizing. So, your code should instead be:

    sheet.autoSizeColumn(0, true);
    
    0 讨论(0)
提交回复
热议问题