1.pom文件
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-jexcel</artifactId>
<version>1.0.6</version>
</dependency>
2.java代码
package com.knife.jxls;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
public class TestJxls {
public static void main(String args[]) throws IOException {
InputStream in = new FileInputStream("H:\\template.xlsx");
OutputStream out = new FileOutputStream("H:\\test1.xlsx");
Context context = new Context();
context.putVar("x","1");
context.putVar("y", "2");
context.putVar("z", "3");
JxlsHelper.getInstance().processTemplate(in, out, context);
}
}
3在模板excel中添加批注
jx:area(lastCell = "D2")
在被批注单元格和lastCell之间的区域会被映射
4.测试结果
模板:
输出文件: