forked from fanruan/easyexcel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
package com.alibaba.easyexcel.test.demo.write; |
|
|
|
import java.util.ArrayList; |
|
import java.util.Date; |
|
import java.util.List; |
|
|
|
import org.junit.Ignore; |
|
import org.junit.Test; |
|
|
|
import com.alibaba.easyexcel.test.util.TestFileUtil; |
|
import com.alibaba.excel.EasyExcelFactory; |
|
|
|
/** |
|
* 写的常见写法 |
|
* |
|
* @author zhuangjiaju |
|
*/ |
|
@Ignore |
|
public class WriteTest { |
|
/** |
|
* 最简单的写 |
|
* <li>1. 创建excel对应的实体对象 参照{@link com.alibaba.easyexcel.test.demo.write.DemoData} |
|
* <li>2. 直接写即可 |
|
*/ |
|
@Test |
|
public void simpleWrite() { |
|
String fileName = TestFileUtil.getPath() + "write" + System.currentTimeMillis() + ".xlsx"; |
|
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后千万别忘记 finish |
|
// 如果这里想使用03 则 传入excelType参数即可 |
|
EasyExcelFactory.write(fileName, DemoData.class).sheet("模板").doWrite(data()).finish(); |
|
} |
|
|
|
private List<DemoData> data() { |
|
List<DemoData> list = new ArrayList<DemoData>(); |
|
for (int i = 0; i < 10; i++) { |
|
DemoData data = new DemoData(); |
|
data.setString("字符串" + 0); |
|
data.setDate(new Date()); |
|
data.setDoubleData(0.56); |
|
list.add(data); |
|
} |
|
return list; |
|
} |
|
}
|
|
|