加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex datagrid 数据导出

发布时间:2020-12-15 04:34:29 所属栏目:百科 来源:网络整理
导读:?//alarmLogExport.action ?/** ? * 日志导出 ? * ? */ ?@SuppressWarnings("unchecked") ?public String alarmLogExport() throws IOException { ?? ?? ? ??? try { ? // AlarmLog 是 model // 数据库查询数据放到 List ListAlarmLog???list = alarmLogServ

?//alarmLogExport.action

?/**
? *
日志导出
? *
? */
?@SuppressWarnings("unchecked")
?public String alarmLogExport() throws IOException {
??
?? ?
??? try {

? // AlarmLog model

//数据库查询数据放到List
List<AlarmLog>???list = alarmLogService.getAlarmLogList(beginTime,endTime,alarmMode,result);
?? } catch (Exception e1) {

?? }

?? response = (HttpServletResponse) ServletActionContext.getResponse();
?? OutputStream os = null;
?? try {
??? os = response.getOutputStream();
?? } catch (IOException e) {

?? }
?? response.reset();
?? response.setHeader("Content-disposition","attachment; filename="
????+ "alarmLog.xls");
?? response.setContentType("application/msexcel");
?? LogExport ?excelExport = new LogExport();
?? inputStream = excelExport.exportAlarmLog(list,os);
?? return SUCCESS;
?}

?

//工具类

//LogExport.java

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.model. AlarmLog;

public class LogExport {

?//警报日志AlarmLog
?public InputStream exportAlarmLog(List<AlarmLog> alarmLog,OutputStream os) throws IOException {
??

??//SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
??//
创建excel
??HSSFWorkbook hwb = new HSSFWorkbook();
??int k = 1;

//创建sheet
??HSSFSheet sheet = hwb.createSheet("
警报日志" + k);
??k++;

//创建标题行
??HSSFRow row1 = sheet.createRow(0);
??row1.createCell(0).setCellValue(new HSSFRichTextString("
通知的用户名"));
??row1.createCell(1).setCellValue(new HSSFRichTextString("
通知的用户组织"));
??row1.createCell(2).setCellValue(new HSSFRichTextString("
通知的用户邮箱"));
??row1.createCell(3).setCellValue(new HSSFRichTextString("
通知的用户电话"));
??row1.createCell(4).setCellValue(new HSSFRichTextString("
警报通知时间"));
??row1.createCell(5).setCellValue(new HSSFRichTextString("
警报内容"));
??
??int row = 0;
??for (int i = 0; i < alarmLog.size(); i++) {
???if (i > 0 && i % 10000 == 0) {
????sheet = hwb.createSheet("
警报日志" + k); // 建立新的BirthSheet对象
????k++;
????row1.createCell(0).setCellValue(new HSSFRichTextString("
通知的用户名"));
????row1.createCell(1).setCellValue(new HSSFRichTextString("
通知的用户组织"));
????row1.createCell(2).setCellValue(new HSSFRichTextString("
通知的用户邮箱"));
????row1.createCell(3).setCellValue(new HSSFRichTextString("
通知的用户电话"));
????row1.createCell(4).setCellValue(new HSSFRichTextString("
警报通知时间"));
????row1.createCell(5).setCellValue(new HSSFRichTextString("
警报内容"));
???}
???HSSFRow row2 = sheet.createRow((row % 10000) + 1);//
创建表格的行
???row2.createCell(0).setCellValue(new HSSFRichTextString(alarmLog.get(i).getUserName()));
???row2.createCell(1).setCellValue(new HSSFRichTextString(alarmLog.get(i).getUserDepart()));
???row2.createCell(2).setCellValue(new HSSFRichTextString(alarmLog.get(i).getUserEmail()));
???row2.createCell(3).setCellValue(new HSSFRichTextString(alarmLog.get(i).getUserTelephone()));
???row2.createCell(4).setCellValue(new HSSFRichTextString(df.format(alarmLog.get(i).getAlarmTime())));
???row2.createCell(5).setCellValue(new HSSFRichTextString(alarmLog.get(i).getAlarmContent()));
???row++;
??}
??try {
???hwb.write(os);
???os.flush();
???return new ByteArrayInputStream(hwb.getBytes());
??} catch (IOException e) {

???return null;
??}
?}

?

}

?

到此就成功导出了。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读