java POI 实现合并单元格

时间:2025-02-16 10:45:55
  • FileOutputStream fos=new FileOutputStream("D:\\");  
  •           
  •         Workbook wb=new HSSFWorkbook();  
  •           
  •         Sheet sheet=();  
  •         /* 
  •          * 设定合并单元格区域范围 
  •          *  firstRow  0-based 
  •          *  lastRow   0-based 
  •          *  firstCol  0-based 
  •          *  lastCol   0-based 
  •          */  
  •         CellRangeAddress cra=new CellRangeAddress(0339);        
  •           
  •         //在sheet里增加合并单元格  
  •         (cra);  
  •           
  •         Row row = (0);  
  •           
  •         Cell cell_1 = (3);  
  •           
  •         cell_1.setCellValue("When you're right , no one remembers, when you're wrong ,no one forgets .");  
  •           
  •         //cell 位置3-9被合并成一个单元格,不管你怎样创建第4个cell还是第5个cell…然后在写数据。都是无法写入的。  
  •         Cell cell_2 = (10);  
  •           
  •         cell_2.setCellValue("what's up ! ");  
  •           
  •         (fos);  
  •           
  •         ();