话不多说上代码
依赖
<dependency>
<!-- LEVEL-PLT:操作EXCEL所需要的包 -->
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<!-- LEVEL-PLT:提供对office的word,excel,visio,ppt的操作 -->
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
</dependency>
代码
public static void createExcel(VBqDocumentPlan plan, VActWfWnProcess wnProcess, String tempFilePath, String outPath) {
try {
// excel模板路径
File fi = new File(tempFilePath);
InputStream in = new FileInputStream(fi);
// 读取excel模板
XSSFWorkbook wb = new XSSFWorkbook(in);
// 读取了模板内所有sheet内容
XSSFSheet sheet = wb.getSheetAt(0);
// 如果这行没有了,整个公式都不会有自动计算的效果的
sheet.setForceFormulaRecalculation(true);
// 在相应的单元格进行赋值
XSSFCell cell = sheet.getRow(2).getCell(4);// 所属部门
if (NullUtil.isNotNull(plan.getRespDeptName())) {
cell