导出 excel 示例

js中: var customermsg_content_exp = $('<div class="customermsg_content_exp">导出拜访记录</div>');

    customer_detail_m.append(customermsg_content_exp);

------------------------------------------------------------------------------------------------------------------------------------------------------------------

              $('.customermsg_content_exp').click(function() {
     customermsg.show(options.customer_id,member_id);

   });

------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * 拜访记录导出
 */
var customermsg = {
appServer:"",
imageServer:"",
url: {
"doExportCustomerMsg" : "/front/exportCustomerMsg.htm"
},

//窗体
addBody:function(param,member_id){
var body = this.body = $('<div class="exportCustomerMsg_div"></div>');
var bmain = $('<div class="bmain"></div>');

bmain.append('<div class="time bmain_bean">时间</div>');

var in_left_div = $('<div  class="in_left bmain_bean"></div>');
bmain.append(in_left_div);
var left_input = $('<input type="text" class="exportCustomerMsg-left" id="exportCustomerMsg-left"/>');
in_left_div.append(left_input);

var style_input_div = $('<div class ="customerexp_style_div bmain_bean"></div>');
var style_input = $('<div class ="customerexp_style_input"></div>');
style_input_div.append(style_input);
bmain.append(style_input_div);

var in_right_div = $('<div  class="in_right bmain_bean"></div>');
bmain.append(in_right_div);
var right_input = $('<input type="text" class="exportCustomerMsg-right" id="exportCustomerMsg-right"/>');
in_right_div.append(right_input);

body.append(bmain);

var op_div = $('<div class="porject_t_box1 customerMsg_btn_box"></div>');
body.append(op_div);
var confirm_btn = $('<a class="porject_t_a1 confirm_btn" href="javascript:void(0)">确定</a>');


op_div.append(confirm_btn);
var cancel_btn = $('<a class="cancel_btn" href="javascript:void(0)">取消</a>');
op_div.append(cancel_btn);


body.find(".exportCustomerMsg-left").focus(function() {
if ($(this).val() == this.defaultValue)
$(this).val("");
WdatePicker({
el : this,
readOnly : true,
dateFmt : "yyyy-MM-dd"
});
});

body.find(".exportCustomerMsg-right").focus(function() {
if ($(this).val() == this.defaultValue)
$(this).val("");
WdatePicker({
el : this,
readOnly : true,
dateFmt : "yyyy-MM-dd"
});
});

var $this = this;
confirm_btn.click(function(){
var sDate = $(".exportCustomerMsg-left").val();
var eDate = $(".exportCustomerMsg-right").val();
var  startTime =  customermsg.parseISO8601(sDate);
var  endTime   = customermsg.parseISO8601(eDate);
if(sDate=="" && eDate==""){
$(".exportCustomerMsg-left").attr("style","border:solid 1px red");
$(".exportCustomerMsg-right").attr("style","border:solid 1px red");
return false;
}
if(sDate=="" ){
$(".exportCustomerMsg-left").attr("style","border:solid 1px red");
return false;
}
if(eDate==""){
$(".exportCustomerMsg-right").attr("style","border:solid 1px red");
return false;
}

var url = customermsg.getUrl("doExportCustomerMsg");
var data = $wq.jsonToArr({
"startTime" : startTime,
"endTime" : endTime,
"customerId":param,
"oid":member_id
});
customermsg.post(url, data);
$this.dialog.close();
});

cancel_btn.click(function(){
if($this.dialog)
$this.dialog.close();
});

return body;
},
post : function(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
if (PARAMS.length > 0) {
for (var i = 0; i < PARAMS.length; i++) {
var opt = document.createElement("textarea");
opt.name = PARAMS[i].name;
opt.value = PARAMS[i].value;
temp.appendChild(opt);
}
}
document.body.appendChild(temp);
temp.submit();
return temp;
},
showDialog: function(param,member_id){
this.dialog =$.dialog({
zIndex: 1060,
title: "导出沟通记录",
content: this.addBody(param,member_id),
close: function(){
},
lock:true,
min:false,
max:false
});
},
close: function(){
this.dialog.close();
},
show: function(customerId,member_id){
customermsg.showDialog(customerId,member_id);
},
getUrl: function(key){
return this.appServer + this.url[key];
},
    parseISO8601 : function(dateStringInRange) {  
  var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/,  
      date = new Date(NaN), month,  
      parts = isoExp.exec(dateStringInRange);  
 
  if(parts) {  
    month = +parts[2];  
    date.setFullYear(parts[1], month - 1, parts[3]);  
    if(month != date.getMonth() + 1) {  
      date.setTime(NaN);  
    }  
  }  
  return date.getTime();  
}  
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------

java中:

/**
* 导出拜访记录
* @return
*/
public String exportCustomerMsgList(){
if (query == null) {
query = new CustomerQuery();
}
User user = getFrontCurrentUser();
query.setMember_id(user.getId());
query.setCompany_id(user.getCo_id());
query.setRole_id(user.getRole_id());
query.setExpsDate(startTime);
query.setExpeDate(endTime);
if (customerId!=null) {
query.setCustomer_id(customerId);
}
if (StringUtil.isNotBlank(oid)) {
query.setOid(oid);
}
HSSFWorkbook book = customerBo.exportCustomerMsg(query);
try {
getResponse().setContentType(
"application/vnd.ms-excel; charset=UTF-8");
getResponse().setHeader(
"Content-Disposition",
"Attachment;filename= "
+ new String("拜访记录信息.xls".toString().getBytes(
"gb2312"), "ISO8859_1"));
OutputStream out = getResponse().getOutputStream();
book.write(out);
out.flush();
out.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------

//拜访记录信息
@Override
public HSSFWorkbook exportCustomerMsg(CustomerQuery query) {
try {
SimpleDateFormat sdf= new SimpleDateFormat("yyyy/MM/dd");  
query.setExpstartTime(sdf.format(new Date(query.getExpsDate()))+" 00:00:00");
query.setExpendTime(sdf.format(new Date(query.getExpeDate()))+" 23:59:59");
query.setStartRow(0);
query.setEndRow(Constant.EXPORT_PAYMENT_COUNT_MAX);
//查询数据
List<CustomerMsgFront> list = customerManMsgBo.exportCustomerMsgList(query);
//初始化表格
HSSFWorkbook workbook = new HSSFWorkbook();
// 生成一个表格
HSSFSheet sheet = workbook.createSheet("拜访记录信息");
sheet.setColumnWidth(0, 20 * 200);// 跟进人
sheet.setColumnWidth(1, 20 * 200);// 拜访时间
sheet.setColumnWidth(2, 20 * 200);// 客户名称
sheet.setColumnWidth(5, 20 * 200);// 地址
sheet.setColumnWidth(3, 20 * 200);// 拜访总结
sheet.setColumnWidth(4, 20 * 300);// 跟进进度
sheet.setColumnWidth(6, 20 * 300);// 拜访地址
sheet.setColumnWidth(7, 20 * 300);// 拜访记录

//新增  12-8
sheet.setColumnWidth(8, 20 * 300);// 联系人姓名
sheet.setColumnWidth(9, 20 * 300);// 交流方式
/**
* 自定义颜色
*/
HSSFPalette palette = workbook.getCustomPalette();
palette.setColorAtIndex((short)10, (byte) 0, (byte) 102, (byte) 203);


// 设置这些样式
HSSFCellStyle titleStyle = workbook.createCellStyle();
titleStyle.setFillForegroundColor((short) 10);
titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);


// 生成一个字体
HSSFFont font = workbook.createFont();
font.setColor(HSSFColor.WHITE.index);
font.setFontHeightInPoints((short) 14);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
titleStyle.setFont(font);


HSSFCellStyle centerStyle = workbook.createCellStyle();
centerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
centerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);


HSSFCellStyle leftStyle = workbook.createCellStyle();
leftStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
leftStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);


HSSFCellStyle rightStyle = workbook.createCellStyle();
rightStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
rightStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

HSSFRow row = sheet.createRow(0);

HSSFCell cell = row.createCell(0);
cell.setCellStyle(titleStyle);
cell.setCellValue("跟进人");


cell = row.createCell(1);
cell.setCellStyle(titleStyle);
cell.setCellValue("时间");

cell = row.createCell(2);
cell.setCellStyle(titleStyle);
cell.setCellValue("客户");

cell = row.createCell(3);
cell.setCellStyle(titleStyle);
cell.setCellValue("地址");

cell = row.createCell(4);
cell.setCellStyle(titleStyle);
cell.setCellValue("内容");

cell = row.createCell(5);
cell.setCellStyle(titleStyle);
cell.setCellValue("跟进进度");


cell = row.createCell(6);
cell.setCellStyle(titleStyle);
cell.setCellValue("拜访地址");

cell = row.createCell(7);
cell.setCellStyle(titleStyle);
cell.setCellValue("拜访记录");

//新增  12-8
cell = row.createCell(8);
cell.setCellStyle(titleStyle);
cell.setCellValue("联系人姓名");
//新增  12-8
cell = row.createCell(9);
cell.setCellStyle(titleStyle);
cell.setCellValue("交流方式");


//循环数据
if (list != null && list.size() > 0) {
SimpleDateFormat dateDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int count = 0;
for (CustomerMsgFront msg : list) {
String name = msg.getMember_name();
String date =  dateDF.format(msg.getRecord_date());
String customer_name = msg.getCustomer_name();
String msg_content = null;
String busi_status = null;
String address = msg.getAddress();
String customer_address = msg.getCustomer_address();
Byte type = msg.getType();

CustomerLinkman c=new CustomerLinkman();
c.setLinkman_id(msg.getLinkman_id());
CustomerLinkman cus=customerLinkmanBo.findOne(c);

String linkman_name=cus.getLink_name();


Byte visit_type=msg.getVisit_type();
String visit_type_name="";
if(visit_type == 1){
visit_type_name = "电话交流";
}else if(visit_type == 2){
visit_type_name = "销售访问";
}else if(visit_type == 3){
visit_type_name = "上门解疑";
}else if(visit_type == 4){
visit_type_name = "销售访问";
}else if(visit_type == 5){
visit_type_name = "上门演示";
}else if(visit_type == 6){
visit_type_name = "参加培训";
}else if(visit_type == 7){
visit_type_name = "客户回访";
}

if (msg.getMsg_content() == null) {
msg_content = null;
} else {
msg_content =msg.getMsg_content();
}

if (msg.getBusi_status() == null) {
busi_status = null;
} else {
busi_status = opCustomerBusiType(msg.getBusi_status());
}

count++; 
HSSFRow content = sheet.createRow(count);
cell = content.createCell(0);
cell.setCellStyle(leftStyle);
cell.setCellValue(name);
cell = content.createCell(1);
cell.setCellStyle(leftStyle);
cell.setCellValue(date);
cell = content.createCell(2);
cell.setCellStyle(leftStyle);
cell.setCellValue(customer_name);
cell = content.createCell(3);
cell.setCellStyle(leftStyle);
cell.setCellValue(customer_address);
cell = content.createCell(4);
cell.setCellStyle(leftStyle);
cell.setCellValue(msg_content);
cell = content.createCell(5);
cell.setCellStyle(leftStyle);
cell.setCellValue(busi_status);
cell = content.createCell(6);
cell.setCellStyle(leftStyle);
cell.setCellValue(address);
cell = content.createCell(7);
cell.setCellStyle(rightStyle);
if (type == CustomerStatusEnum.NORMAL.value()) {
cell.setCellValue("拜访记录");
}else {
cell.setCellValue("沟通记录");
}



/**
* 新增
* 12-8
*/
cell = content.createCell(8);
cell.setCellStyle(leftStyle);
cell.setCellValue(linkman_name);
cell = content.createCell(9);
cell.setCellStyle(leftStyle);
cell.setCellValue(visit_type_name);
}
}
return workbook;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值