部分代码如下:(setCell是我自己封装的方法)
cell=setCell(1,2,sheet1);//第一行第二格
cell.setCellValue("AAA");
cell=setCell(1,3,sheet1);//第一行第三格
cell.setCellValue("bbb");
wb.setRepeatingRowsAndColumns(0,1,2,0,0);//合并2,3格但是不行输出还是分开的两格,多谢帮忙

解决方案 »

  1.   

    试试这个
    sheet.addMergedRegion(new Region(1,(short)2,1,(short)3));
      

  2.   

    POI自带例子:import org.apache.poi.hssf.usermodel.*;
    import org.apache.poi.hssf.util.Region;import java.io.IOException;
    import java.io.FileOutputStream;/**
     * An example of how to merge regions of cells.
     *
     * @author Glen Stampoultzis (glens at apache.org)
     */
    public class MergedCells
    {
       public static void main(String[] args)
            throws IOException
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("new sheet");        HSSFRow row = sheet.createRow((short) 1);
            HSSFCell cell = row.createCell((short) 1);
            cell.setCellValue("This is a test of merging");        sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));        // Write the output to a file
            FileOutputStream fileOut = new FileOutputStream("workbook.xls");
            wb.write(fileOut);
            fileOut.close();    }
    }
      

  3.   

    能解释一下Region(1,(short)1,1,(short)2)这个方法中的四个参数的意思吗,方法后面的1和(short)2分别合并竖行和横行但是值大于3之后好像合并的就不准确了哪个大虾能帮小弟一下吗