poi导出java代码 java使用poi导出excel

Java 利用poi 导出excel表格如何在导出时自由选择路径?导出时自由选择路径的代码如下poi导出java代码:
1、后台输出Excel文件代码poi导出java代码:
OutputStream output = response.getOutputStream();
response.reset();
response.setHeader("Content-disposition", "attachment; filename=" + path);
response.setContentType("Content-Type:application/vnd.ms-excel ");
wb.write(output);
output.close();
2、前端代码:
window.open("getExcelList","_blank");
导出excel数据
* @param id
* @param m
* @return
*/
@RequestMapping("/exportExcel")
public void exportExcel(@RequestParam("id") Integer id, Model m,HttpServletRequest req, HttpServletResponse resp) {
try {
ExportExcelP2pLoanPlanVo ex = new ExportExcelP2pLoanPlanVo();
String[] headers = {"最迟还款日", "还款金额","剩余几天","逾期几天", "罚息","是否垫付","状态","是否发放收益"};
ListP2pLoanPlanVo dataset = new ArrayListP2pLoanPlanVo();
ListP2pLoanPlan plans = this.planService.getListByLoan(id);
for (int i = 0; iplans.size(); i++) {
P2pLoanPlanVo p2pLoanPlanVo = new P2pLoanPlanVo();
p2pLoanPlanVo.setRepayDate(plans.get(i).getRepayDate());
p2pLoanPlanVo.setRepayAmount(plans.get(i).getRepayAmount());
if(plans.get(i).getRepayDays() = 0plans.get(i).getStatus() == 0){
p2pLoanPlanVo.setRepayDays(plans.get(i).getRepayDays());
}else{
p2pLoanPlanVo.setRepayDays(0);
}
if(plans.get(i).getRepayDays()0plans.get(i).getStatus() == 0){
p2pLoanPlanVo.setRepayYqDays(-plans.get(i).getRepayDays());
}else{
p2pLoanPlanVo.setRepayYqDays(0);
}
java如何导出excel表格,如果用poi,java代码如何实现.,求代码?。。?/h2>项目结构poi导出java代码:
xls:
\\\
XlsMain .java 类
//该类有main方法poi导出java代码 , 主要负责运行程序,同时该类中也包含了用poi读取Excel(2003版)
*
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
*
* @author Hongten/br
*
*参考地址:
*
*/
public class XlsMain {
public static void main(String[] args) throws IOException {
XlsMain xlsMain = new XlsMain();
XlsDto xls = null;
ListXlsDto list = xlsMain.readXls();
try {
XlsDto2Excel.xlsDto2Excel(list);
} catch (Exception e) {
e.printStackTrace();
}
for (int i = 0; ilist.size(); i++) {
xls = (XlsDto) list.get(i);
System.out.println(xls.getXh() + "" + xls.getXm() + ""
+ xls.getYxsmc() + "" + xls.getKcm() + ""
+ xls.getCj());
}
}
/**
* 读取xls文件内容
*
* @return ListXlsDto对象
* @throws IOException
*输入/输出(i/o)异常
*/
private ListXlsDto readXls() throws IOException {
InputStream is = new FileInputStream("pldrxkxxmb.xls");
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
XlsDto xlsDto = null;
ListXlsDto list = new ArrayListXlsDto();
// 循环工作表Sheet
for (int numSheet = 0; numSheethssfWorkbook.getNumberOfSheets(); numSheet++) {
HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
if (hssfSheet == null) {
continue;
}
// 循环行Row
for (int rowNum = 1; rowNum = hssfSheet.getLastRowNum(); rowNum++) {
HSSFRow hssfRow = hssfSheet.getRow(rowNum);
if (hssfRow == null) {
continue;
}
xlsDto = new XlsDto();
// 循环列Cell

推荐阅读