JXLS for循环

1.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 java.util.ArrayList;
import java.util.List;

import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;

public class TestJxls {

	public static class Foo {

		public String id;
		public String name;
		public int age;

		public Foo(String id, String name, int age) {
			this.id = id;
			this.name = name;
			this.age = age;
		}

	}

	public static void main(String args[]) throws IOException {

		List foolist=new ArrayList();
		foolist.add(new Foo("001","lee",11));
		foolist.add(new Foo("002","wang",14));
		foolist.add(new Foo("003","zhang",19));
		
		InputStream in = new FileInputStream("H:\\template.xlsx");
		OutputStream out = new FileOutputStream("H:\\test1.xlsx");
		Context context = new Context();
		context.putVar("foolist", foolist);
		JxlsHelper.getInstance().processTemplate(in, out, context);
	}

}

2.批注

jx:area(lastCell = "D4")
jx:each(items="foolist" var="foo" lastCell="D4")

3.结果

模板:

JXLS for循环_第1张图片

输出文件:

JXLS for循环_第2张图片

你可能感兴趣的:(JXLS for循环)