更新时间:2022-05-19 17:35:27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package csg.xiaoye.poidemo;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
public class PoiSpaceMer {
public static void main(String[] args) throws Exception{
Workbook wb= new HSSFWorkbook(); // 定义一个新的工作簿
Sheet sheet=wb.createSheet( "第一个Sheet页" ); // 创建第一个Sheet页
Row row=sheet.createRow( 1 ); // 创建一个行
Cell cell=row.createCell( 1 );
cell.setCellValue( "单元格合并测试" );
sheet.addMergedRegion( new CellRangeAddress(
1 , // 起始行
2 , // 结束行
1 , // 其实列
2 // 结束列
));
FileOutputStream fileOut= new FileOutputStream( "d:\\小夜.xls" );
wb.write(fileOut);
fileOut.close();
}
} |
效果如下: