参考文章
POI常用类说明
HSSFWorkbook<------>Excel的文档对象
HSSFSheet<------>Excel的表单
HSSFRow<------>Excel的行
HSSFCell<------>Excel的格子单元
HSSFFont<------>Excel字体
HSSFDataFormat<------>格子单元的日期格式
HSSFHeader<------>Excel文档Sheet的页眉
HSSFFooter<------>Excel文档Sheet的页脚
HSSFCellStyle<------>格子单元样式
HSSFDateUtil<------>日期
HSSFPrintSetup<------>打印
HSSFErrorConstants<------>错误信息表
package mytest;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
public class test001 {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("BOM报表");
HSSFRow row1 = sheet.createRow(0);
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFCell cell = row1.createCell(0);
cell.setCellValue("BOM报表");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
HSSFRow row2 = sheet.createRow(1);
row2.createCell(0).setCellValue("父id");
row2.createCell(1).setCellValue("父名称");
row2.createCell(2).setCellValue("父版本id");
row2.createCell(3).setCellValue("父版本id");
row2.createCell(4).setCellValue("子id");
row2.createCell(5).setCellValue("子名称");
row2.createCell(6).setCellValue("数量");
row2.createCell(7).setCellValue("总数量");
HSSFRow row3 = sheet.createRow(2);
row3.createCell(0).setCellValue(1);
row3.createCell(1).setCellValue(1);
row3.createCell(2).setCellValue(1);
row3.createCell(3).setCellValue(1);
row3.createCell(4).setCellValue(1);
row3.createCell(5).setCellValue(1);
row3.createCell(6).setCellValue(1);
row3.createCell(7).setCellValue(1);
HSSFRow row4 = sheet.createRow(3);
row4.createCell(0).setCellValue(2);
row4.createCell(1).setCellValue(2);
row4.createCell(2).setCellValue(2);
row4.createCell(3).setCellValue(2);
row4.createCell(4).setCellValue(2);
row4.createCell(5).setCellValue(2);
row4.createCell(6).setCellValue(2);
row4.createCell(7).setCellValue(2);
FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\" + "BOM报表.xls");
wb.write(fileOutputStream);
fileOutputStream.close();
System.out.println("=========输出Excel文件,成功!!=====");
}
}
|