本文概述
- Apache POI Excel标头示例
让我们看一个示例,其中我们将为文档创建和设置标题。
Apache POI Excel标头示例
package poiexample;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Header;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class HeaderExample {
public static void main(String[] args) {
try (OutputStream fileOut = new FileOutputStream("srcmini.xls")) {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet");
// Creating Header
Header header = sheet.getHeader();
header.setCenter("Center Header");
header.setLeft("Left Header");
header.setRight ("Right align Header");
// Creating Row
Row row = sheet.createRow(4);
// Creating a row
Cell cell = row.createCell(1);
// Creating a cell
cell.setCellValue("Hello, srcmini!");
wb.write(fileOut);
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
输出:
此输出是文件的printview。
文章图片
推荐阅读
- apache poi隐藏行
- apache poi excel字体
- apache poi合并单元
- apache poi excel单元格颜色
- apache poi excel单元格边界
- apache poi excel单元格
- apache poi excel对齐单元格
- apache poi excel日期单元格
- apache poi excel工作簿