ts获取服务器数据_怎么使用Satruts2实现页面列表数据导出到Excel表格
Java codeprivate InputStream excelFile;
public void setExcelFile(InputStream excelFile) {
this.excelFile = excelFile;
}
public InputStream getExcelFile() {
return excelFile;
}
public String createExcelFile() {
try {
String[] headName = { "昵稱","電子郵箱"};
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("sheet1");
// 創(chuàng)建表頭
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
for (int i = 0; i < headName.length; i++) {
cell = row.createCell((short) i);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue(headName[i]);
}
for (int i = 0; i < cwcsList.size(); i++) {
row = sheet.createRow(i + 1);
//昵稱
cell = row.createCell((short) 0);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue(cwcsList.get(i).getCusName());
// 電子郵箱
cell = row.createCell((short) 1);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue(cwcsList.get(i).getEmail());
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
workbook.write(baos);
byte[] ba = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(ba);
this.setExcelFile(bais);
} catch (IOException e) {
e.printStackTrace();
}
return "exportExcel"
}
總結(jié)
以上是生活随笔為你收集整理的ts获取服务器数据_怎么使用Satruts2实现页面列表数据导出到Excel表格的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为FreeBuds 5星河蓝配色开售:
- 下一篇: totolinkn200up怎么设置_t