您的位置:首页 > 运维架构 > Shell

Powershell 导出Exchange 用户 EmailAddresses属性

2014-12-04 14:28 302 查看
/**
* 设置单元格值
* @param wb
* @param cell
* @param sale
*/
public static void setBodyCellValue(HSSFWorkbook wb,HSSFCell cell,String sale){
CellStyle style = cell.getCellStyle();

Pattern p = Pattern.compile("^\\d+$");
Matcher matcher = p.matcher(sale);
Pattern p2 = Pattern.compile("^[-]?\\d+[.]{1}\\d+[%]{1}$");
Matcher matcher2 = p2.matcher(sale);
Pattern p3 = Pattern.compile("^\\d+[\\d|,]+$");//千分位 如355,656
Matcher matcher3 = p3.matcher(sale);

if (matcher.matches()) {// 是数字当作double处理
cell.setCellValue(Double.parseDouble(sale));
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
cell.setCellStyle(style);
}else if (matcher2.matches()) {//百分比
sale = sale.replace("%", "");
Double d = Double.parseDouble(sale)/100;
cell.setCellValue(d);
//设置百分比格式
String formart = "0.";
if(sale.contains(".")){
sale = sale.replace(".", "#");
String numArr[] = sale.split("#");
String ss = "";
if(numArr!=null&&numArr.length==2){
int length = numArr[1].length();
for (int i = 0; i < length; i++) {
ss+="0";
}
}else{
ss="0";
}
formart+=ss;
}else{
formart+="0";
}
formart+="%";
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
style.setDataFormat(wb.createDataFormat().getFormat(formart));
cell.setCellStyle(style);
}else if(matcher3.matches()){
sale = sale.replace(",", "");
Integer salesNum = Integer.valueOf(sale);
cell.setCellValue(salesNum);
style.setDataFormat(wb.createDataFormat().getFormat("#,##0"));
cell.setCellStyle(style);
}
else{//字符串
cell.setCellValue(sale+" ");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: