@@ -46,7 +46,16 @@ EasyPoi的几个入口工具类 | |||||
- 2.0.6-SNAPSHOT | - 2.0.6-SNAPSHOT | ||||
- 增加map的导出 | - 增加map的导出 | ||||
- 增加index 列 | - 增加index 列 | ||||
--------------------------- | |||||
EasyPoi 文档 | |||||
--------------------------- | |||||
[EasyPoi-在财务报表中的应用](http://git.oschina.net/jueyue/easypoi/wikis/EasyPoi-%E5%9C%A8%E8%B4%A2%E5%8A%A1%E6%8A%A5%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8) | |||||
[EasyPoi-如何筛选导出属性](http://git.oschina.net/jueyue/easypoi/wikis/EasyPoi-%E5%A6%82%E4%BD%95%E7%AD%9B%E9%80%89%E5%AF%BC%E5%87%BA%E5%B1%9E%E6%80%A7) | |||||
--------------------------- | --------------------------- | ||||
EasyPoi导出实例 | EasyPoi导出实例 | ||||
--------------------------- | --------------------------- | ||||
@@ -0,0 +1,28 @@ | |||||
package org.jeecgframework.poi.entity; | |||||
import org.jeecgframework.poi.excel.annotation.Excel; | |||||
public class TestEntity { | |||||
@Excel(name = "蓝牙POS机") | |||||
private String lanya; | |||||
@Excel(name = "蓝牙点付宝") | |||||
private String pos; | |||||
public String getLanya() { | |||||
return lanya; | |||||
} | |||||
public void setLanya(String lanya) { | |||||
this.lanya = lanya; | |||||
} | |||||
public String getPos() { | |||||
return pos; | |||||
} | |||||
public void setPos(String pos) { | |||||
this.pos = pos; | |||||
} | |||||
} |
@@ -0,0 +1,34 @@ | |||||
package org.jeecgframework.poi.entity.temp; | |||||
import org.jeecgframework.poi.excel.annotation.Excel; | |||||
/** | |||||
* 预算 | |||||
* @author JueYue | |||||
* @date 2014年12月27日 下午9:08:03 | |||||
*/ | |||||
public class BudgetAccountsEntity { | |||||
@Excel(name = "编码") | |||||
private String code; | |||||
@Excel(name = "名称") | |||||
private String name; | |||||
public String getCode() { | |||||
return code; | |||||
} | |||||
public void setCode(String code) { | |||||
this.code = code; | |||||
} | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public void setName(String name) { | |||||
this.name = name; | |||||
} | |||||
} |
@@ -0,0 +1,40 @@ | |||||
package org.jeecgframework.poi.entity.temp; | |||||
import org.jeecgframework.poi.excel.annotation.Excel; | |||||
public class PayeeEntity { | |||||
@Excel(name = "全称") | |||||
private String name; | |||||
@Excel(name = "银行账号") | |||||
private String bankAccount; | |||||
@Excel(name = "开户银行") | |||||
private String bankName; | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public void setName(String name) { | |||||
this.name = name; | |||||
} | |||||
public String getBankAccount() { | |||||
return bankAccount; | |||||
} | |||||
public void setBankAccount(String bankAccount) { | |||||
this.bankAccount = bankAccount; | |||||
} | |||||
public String getBankName() { | |||||
return bankName; | |||||
} | |||||
public void setBankName(String bankName) { | |||||
this.bankName = bankName; | |||||
} | |||||
} |
@@ -0,0 +1,99 @@ | |||||
package org.jeecgframework.poi.entity.temp; | |||||
import java.io.Serializable; | |||||
import java.util.List; | |||||
import org.jeecgframework.poi.excel.annotation.Excel; | |||||
import org.jeecgframework.poi.excel.annotation.ExcelCollection; | |||||
import org.jeecgframework.poi.excel.annotation.ExcelEntity; | |||||
/** | |||||
* 模板导出 测试类 | |||||
* @author JueYue | |||||
* @date 2014年12月26日 上午9:39:13 | |||||
*/ | |||||
public class TemplateExcelExportEntity implements Serializable { | |||||
/** | |||||
* | |||||
*/ | |||||
private static final long serialVersionUID = 1L; | |||||
@Excel(name = "序号") | |||||
private String index; | |||||
@Excel(name = "资金性质") | |||||
private String accountType; | |||||
@ExcelCollection(name = "预算科目") | |||||
private List<BudgetAccountsEntity> budgetAccounts; | |||||
@Excel(name = "项目名称") | |||||
private String projectName; | |||||
@ExcelEntity(name = "收款人") | |||||
private PayeeEntity payee; | |||||
@Excel(name = "申请金额") | |||||
private String amountApplied; | |||||
@Excel(name = "核定金额") | |||||
private String approvedAmount; | |||||
public String getIndex() { | |||||
return index; | |||||
} | |||||
public void setIndex(String index) { | |||||
this.index = index; | |||||
} | |||||
public String getAccountType() { | |||||
return accountType; | |||||
} | |||||
public void setAccountType(String accountType) { | |||||
this.accountType = accountType; | |||||
} | |||||
public List<BudgetAccountsEntity> getBudgetAccounts() { | |||||
return budgetAccounts; | |||||
} | |||||
public void setBudgetAccounts(List<BudgetAccountsEntity> budgetAccounts) { | |||||
this.budgetAccounts = budgetAccounts; | |||||
} | |||||
public String getProjectName() { | |||||
return projectName; | |||||
} | |||||
public void setProjectName(String projectName) { | |||||
this.projectName = projectName; | |||||
} | |||||
public PayeeEntity getPayee() { | |||||
return payee; | |||||
} | |||||
public void setPayee(PayeeEntity payee) { | |||||
this.payee = payee; | |||||
} | |||||
public String getAmountApplied() { | |||||
return amountApplied; | |||||
} | |||||
public void setAmountApplied(String amountApplied) { | |||||
this.amountApplied = amountApplied; | |||||
} | |||||
public String getApprovedAmount() { | |||||
return approvedAmount; | |||||
} | |||||
public void setApprovedAmount(String approvedAmount) { | |||||
this.approvedAmount = approvedAmount; | |||||
} | |||||
} |
@@ -4,13 +4,15 @@ import java.io.File; | |||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.commons.lang.StringUtils; | |||||
import org.jeecgframework.poi.entity.CourseEntity; | import org.jeecgframework.poi.entity.CourseEntity; | ||||
import org.jeecgframework.poi.entity.TestEntity; | |||||
import org.jeecgframework.poi.excel.entity.ImportParams; | import org.jeecgframework.poi.excel.entity.ImportParams; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
public class ExcelImportUtilTest { | public class ExcelImportUtilTest { | ||||
@Test | |||||
//@Test | |||||
public void test() { | public void test() { | ||||
ImportParams params = new ImportParams(); | ImportParams params = new ImportParams(); | ||||
params.setTitleRows(2); | params.setTitleRows(2); | ||||
@@ -18,9 +20,31 @@ public class ExcelImportUtilTest { | |||||
//params.setSheetNum(9); | //params.setSheetNum(9); | ||||
params.setNeedSave(true); | params.setNeedSave(true); | ||||
long start = new Date().getTime(); | long start = new Date().getTime(); | ||||
List<CourseEntity> list = ExcelImportUtil.importExcel(new File("d:/tt.xls"), | |||||
List<CourseEntity> list = ExcelImportUtil.importExcel(new File("d:/tt.xlsx"), | |||||
CourseEntity.class, params); | CourseEntity.class, params); | ||||
System.out.println(list.size() + "-----" + (new Date().getTime() - start)); | System.out.println(list.size() + "-----" + (new Date().getTime() - start)); | ||||
} | } | ||||
@Test | |||||
public void test2() { | |||||
ImportParams params = new ImportParams(); | |||||
params.setTitleRows(1); | |||||
params.setHeadRows(1); | |||||
params.setSheetNum(8); | |||||
//params.setSheetNum(9); | |||||
long start = new Date().getTime(); | |||||
List<TestEntity> list = ExcelImportUtil.importExcel(new File("d:/tt.xlsx"), | |||||
TestEntity.class, params); | |||||
String str = ""; | |||||
for (int i = 0; i < list.size(); i++) { | |||||
if (StringUtils.isNotEmpty(list.get(i).getLanya())) { | |||||
str += "','" + Double.valueOf(list.get(i).getLanya()).intValue(); | |||||
} | |||||
if (StringUtils.isNotEmpty(list.get(i).getPos())) { | |||||
str += "','" + Double.valueOf(list.get(i).getPos()).intValue(); | |||||
} | |||||
} | |||||
System.out.println(str); | |||||
System.out.println(str.split(",").length); | |||||
} | |||||
} | } |
@@ -0,0 +1,80 @@ | |||||
package org.jeecgframework.poi.excel.template; | |||||
import static org.junit.Assert.*; | |||||
import java.io.File; | |||||
import java.io.FileOutputStream; | |||||
import java.util.ArrayList; | |||||
import java.util.Date; | |||||
import java.util.HashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.jeecgframework.poi.entity.statistics.StatisticEntity; | |||||
import org.jeecgframework.poi.entity.temp.BudgetAccountsEntity; | |||||
import org.jeecgframework.poi.entity.temp.PayeeEntity; | |||||
import org.jeecgframework.poi.entity.temp.TemplateExcelExportEntity; | |||||
import org.jeecgframework.poi.excel.ExcelExportUtil; | |||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams; | |||||
import org.junit.Test; | |||||
import com.google.common.collect.Lists; | |||||
public class TemplateExcelExportTest { | |||||
@Test | |||||
public void test() throws Exception { | |||||
TemplateExportParams params = new TemplateExportParams( | |||||
"org/jeecgframework/poi/excel/doc/专项支出用款申请书.xls"); | |||||
params.setHeadingStartRow(3); | |||||
params.setHeadingRows(2); | |||||
Map<String, Object> map = new HashMap<String, Object>(); | |||||
map.put("date", "2014-12-25"); | |||||
map.put("money", 2000000.00); | |||||
map.put("upperMoney", "贰佰万"); | |||||
map.put("company", "执笔潜行科技有限公司"); | |||||
map.put("bureau", "财政局"); | |||||
map.put("person", "JueYue"); | |||||
map.put("phone", "1879740****"); | |||||
List<TemplateExcelExportEntity> list = new ArrayList<TemplateExcelExportEntity>(); | |||||
for (int i = 0; i < 1; i++) { | |||||
TemplateExcelExportEntity entity = new TemplateExcelExportEntity(); | |||||
entity.setIndex(i + 1 + ""); | |||||
entity.setAccountType("开源项目"); | |||||
entity.setProjectName("EasyPoi " + i + "期"); | |||||
entity.setAmountApplied(i * 10000 + ""); | |||||
entity.setApprovedAmount((i + 1) * 10000 - 100 + ""); | |||||
List<BudgetAccountsEntity> budgetAccounts = Lists.newArrayList(); | |||||
for (int j = 0; j < 1; j++) { | |||||
BudgetAccountsEntity accountsEntity = new BudgetAccountsEntity(); | |||||
accountsEntity.setCode("A001"); | |||||
accountsEntity.setName("设计"); | |||||
budgetAccounts.add(accountsEntity); | |||||
accountsEntity = new BudgetAccountsEntity(); | |||||
accountsEntity.setCode("A002"); | |||||
accountsEntity.setName("开发"); | |||||
budgetAccounts.add(accountsEntity); | |||||
} | |||||
entity.setBudgetAccounts(budgetAccounts); | |||||
PayeeEntity payeeEntity = new PayeeEntity(); | |||||
payeeEntity.setBankAccount("6222 0000 1234 1234"); | |||||
payeeEntity.setBankName("中国银行"); | |||||
payeeEntity.setName("小明"); | |||||
entity.setPayee(payeeEntity); | |||||
list.add(entity); | |||||
} | |||||
Workbook workbook = ExcelExportUtil.exportExcel(params, TemplateExcelExportEntity.class, | |||||
list, map); | |||||
File savefile = new File("d:/"); | |||||
if (!savefile.exists()) { | |||||
savefile.mkdirs(); | |||||
} | |||||
FileOutputStream fos = new FileOutputStream("d:/tt.xls"); | |||||
workbook.write(fos); | |||||
fos.close(); | |||||
} | |||||
} |