javapoi导出excell设置了setCellStyle单远格的数据变成空

博客分类:
import java.io.FileOutputS
import java.io.IOE
import java.util.D
import org.apache.poi.hssf.usermodel.HSSFC
import org.apache.poi.hssf.usermodel.HSSFCellS
import org.apache.poi.hssf.usermodel.HSSFDataF
import org.apache.poi.hssf.usermodel.HSSFFimport org.apache.poi.hssf.usermodel.HSSFR
import org.apache.poi.hssf.usermodel.HSSFS
import org.apache.poi.hssf.usermodel.HSSFW
import org.apache.poi.hssf.util.HSSFC
import org.apache.poi.ss.util.CellRangeA
public class CreateCells {
* 文档对象 HSSFW表单对象 HSSFS行对象 HSSFR列对象 HSSFCell
* excell的格子单元 HSSFFont excell字体 HSSFName 名称 HSSFDataFormat 日期格式 HSSFHeader
* sheet头 HSSFFooter sheet尾 HSSFCellStyle cell样式
public static void main(String[] args) throws IOException {
// 建立新HSSFWorkbook对象
HSSFWorkbook workbook = new HSSFWorkbook();
// 建立新的sheet对象
// Create a row and put some cells in it.Rows are 0 based.
HSSFSheet sheet = workbook.createSheet("表单1");
// 建立新行
// Create a cell and put a value in it.
HSSFRow row = sheet.createRow((short) 0);
//修改当前行 默认行高
sheet.setDefaultRowHeightInPoints(10);
sheet.setDefaultColumnWidth(10);
//设置特定单元格的宽度
sheet.setColumnWidth(4, 20*256);
sheet.setColumnWidth(5, 30*256);
sheet.setColumnWidth(6, 30*256);
// 整数类型的cell样式
//HSSFDataFormat.getBuiltinFormat("0.00")
字符串的内容是
Excel有的格式
HSSFCellStyle numStyle = workbook.createCellStyle();
numStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
HSSFCell cellNum = row.createCell(0);
cellNum.setCellValue(1);
cellNum.setCellStyle(numStyle);
// 浮点类型的cell样式
HSSFCellStyle doubleStyle = workbook.createCellStyle();
doubleStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
HSSFCell cellDouble = row.createCell(1);
cellDouble.setCellValue(1.2);
cellDouble.setCellStyle(doubleStyle);
//字符串类型的cell样式
HSSFCellStyle stringStyle = workbook.createCellStyle();
stringStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("G/通用格式"));
HSSFCell cellString= row.createCell(2);
cellString.setCellValue("test");
cellString.setCellStyle(stringStyle);
//添加cell布尔类型的值
row.createCell(3).setCellValue(true);
//日期类型的cell样式
h:mm:ss AM/PM
HSSFCellStyle dateStyle = workbook.createCellStyle();
dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
HSSFCell dCell = row.createCell(4);
dCell.setCellValue(new Date());
dCell.setCellStyle(dateStyle);
//设置cell编码解决中文高位字节截断
HSSFCell csCell = row.createCell(5);
csCell.setCellType(HSSFCell.ENCODING_UTF_16);
csCell.setCellValue("中文测试_Chinese Words Test");
HSSFCellStyle style1 = workbook.createCellStyle();
//前景色和后景色都要有
否则会出网格
style1.setFillForegroundColor(new HSSFColor.YELLOW().getIndex());
style1.setFillBackgroundColor(new HSSFColor.YELLOW().getIndex());
//设置边框
style1.setBorderBottom((short) 1);
style1.setBorderTop((short) 1);
style1.setBorderLeft((short) 1);
style1.setBorderRight((short) 1);
//问题:用poi将一个cell中的字体设置成了红色,结果用excell打开后,这个cell中只有前面一个或几个字为红色
//HSSFFont
workbook.createFont();
font.setColor(HSSFFont.COLOR_RED);
//先從Cell中把HSSFRichTextString取出來
//然后HSSFRichTextString對象.applyFont(font)
//最后再把HSSFRichTextString對象set回到cell中就行了。。。。。
//设置字体样式=====================================
workbook.createFont();
//字体位置
上 下 左 右
//font.setTypeOffset((short)0);
//字体宽度
font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
//字体高度
font.setFontHeightInPoints((short)8);
//字体颜色
font.setColor(HSSFFont.COLOR_RED);
//=================================================
style1.setFont(font);
* 注意这句代码, style1.setFillPattern, 如果你在你的程序中不设置fill pattern,那么
* 你上面设置的前景色和背景色就显示不出来.网络上很多文章都没有设置fillpattern
* 如果不改变样式
不需要添加(如:居中)
style1.setFillPattern(HSSFCellStyle.SPARSE_DOTS);
HSSFCell cellCH = row.createCell(6);
cellCH.setCellValue("中文测试_Chinese Words Testsss");
cellCH.setCellStyle(style1);
//货币样式
HSSFCellStyle moneyStyle = workbook.createCellStyle();
moneyStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
HSSFCell cell12 = row.createCell(7);
cell12.setCellValue((double) );
cell12.setCellStyle(moneyStyle);
// 错误显示
row.createCell(8).setCellType(HSSFCell.CELL_TYPE_ERROR);
//合并单元格
int startRowNo=0;
int endRowNo=0;
int startCellNo=9;
int endCellNo=10;
sheet.addMergedRegion(new CellRangeAddress(startRowNo, endRowNo,startCellNo, endCellNo));
HSSFCell cell = row.createCell(9);
cell.setCellValue("合并");
//即垂直居中对齐且水平居中对齐
居中后背景颜色变化了
HSSFCellStyle style = workbook.createCellStyle();
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平
//如果不改变样式
不需要添加
//style.setFillPattern(HSSFCellStyle.SPARSE_DOTS);
cell.setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream("e:/workbook.xls");
workbook.write(fileOut);
fileOut.close();
浏览 10851
ruanjiangjx
浏览: 56274 次
来自: 北京
重新修改了方法,支持
方法重载功能!
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'POI导出EXCEL 设置某列的字体颜色
<a data-traceid="question_detail_above_text_l&&
想动态改变某一列的字体颜色为红色,总实现不了???
// 生成一个表格
HSSFSheet sheet = workbook.createSheet();
workbook.setSheetName(sheetNum, sheetTitle);
// 设置表格默认列宽度为17个字节
sheet.setDefaultColumnWidth(15);
sheet.createFreezePane(4, 0); //冻结列:冻结前四列
sheet.setColumnWidth(0, 2000); //设置宽度 (excel的宽度单位不同)
sheet.setColumnWidth(1, 2500);
sheet.setColumnWidth(2, 1700);
sheet.setColumnWidth(3, 2000);
// 生成一个样式
HSSFCellStyle style = workbook.createCellStyle();
HSSFCellStyle style2 = workbook.createCellStyle();
// 设置这些样式
style.setFillForegroundColor(HSSFColor.WHITE.index);// 以给单元格着色
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //设置单元格填充样式 SOLID_FOREGROUND纯色使用前景颜色填充
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN); // 设置边界的类型单元格的左边框
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 设置单元格为水平对齐的类型
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //设置垂直居中
style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 生成一个字体
HSSFFont font = workbook.createFont();
font.setColor(HSSFColor.BLACK.index);
font.setColor(IndexedColors.BLACK.getIndex());
font.setFontName("宋体"); //设置字体
font.setFontHeightInPoints((short) 11); //设置字号
font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); //设置字体样式 正常显示
// 把字体应用到当前的样式
style2.setFont(font);
style.setFont(font);
// 指定当单元格内容显示不下时自动换行
style.setWrapText(true);
style2.setWrapText(true);
// 产生表格标题行
HSSFRow row = sheet.createRow(0);
for (int i = 0; i & headers. i++)
HSSFCell cell = row.createCell(i);
cell.setCellStyle(style);
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text.toString());
// 遍历集合数据,产生数据行
if (result != null)
int index = 1;
int fieldLength = new ExportBean().getClass().getDeclaredFields().length -1;
for (ExportBean bean : result)
row = sheet.createRow(index);
int cellIndex = 0;
Field[] fields = bean.getClass().getDeclaredFields(); //反射获取值
for (int i = 1; i &= fieldL i++)
Field f = fields[i];
f.setAccessible(true); //设置可见性
Object val = f.get(bean);
HSSFCell cell = row.createCell(cellIndex);
cell.setCellValue(val.toString());
cell.setCellStyle(style2);
cellIndex++;poi导出的excel的数字小数位过多?
时间: 00:33:12
&&&& 阅读:1341
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&  最近在使用Apache的POI组件对Excel进行操作,在对excel导出的时候,导出的数字本来只有两位小数,得到的结果就变成了很多位小数。如下面的图所示:
  虽然对单元格使用了setCellStyle,但还是治标不治本,显示虽然是只显示两位小数了,但是点开还是有很长的一串小数位,这很不爽,这什么原因导致的呢?我们来看看。
  我首先debug看一下,在设置单元格的值时候,数据一切正常,数据库读出的数据也为0.44,没看出一点猫腻。随后我再仔细看看,在看到cell.setCellValue(double arg0)里面的参数是double的时候,感觉到一点不对劲,再看看Model,发现该成员变量是float,敏感的同学应该一眼就看出来了,没错,就是float转double的时候精度变得更细了。
  关于float和double的关系,我推荐看一下这个文章:。大概就是double比float拥有更长的指数位和尾数位,在指数位不影响的情况下,float的数值转化为二进制数值的时候,小数乘以2的时候无法得出1,导致尾数位是无限的01,而double拥有更长的尾数位,所以double的01比float更多,得出的结果也就不一样,也就是说double比float的精度更精确。
  那么怎么解决这个问题呢?其实就是float转double的精度问题,
  1、将Model的成员变量改为double。(不干,太麻烦,还要改数据库什么的)
  2、使用BigDecimal的setScale
  3、Double.parseDouble(String.valueOf(number))标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:http://www.cnblogs.com/ginponson/p/5145591.html
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!java操作poi的excel表格的线条怎么变为黑色?_百度知道
java操作poi的excel表格的线条怎么变为黑色?
&#xe6b9;答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
采纳数:18
获赞数:50
你跑下下面的代码试下吧:public TestExcel(){
createExcelFile(); }
private void createExcelFile() {
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet(&test sheet&);
//创建一个样式
HSSFCellStyle style = hwb.createCellStyle();
//设置边框样式
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
//设置边框颜色
style.setTopBorderColor(HSSFColor.BLACK.index);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setLeftBorderColor(HSSFColor.BLACK.index);
style.setRightBorderColor(HSSFColor.BLACK.index);
for(int j=0;j&5;j++){
HSSFRow row = sheet.createRow(j);
for(int i=0;i&10;i++){
HSSFCell cell = row.createCell(i);
cell.setCellStyle(style);
cell.setCellValue(j+&*&+i);
File file = new File(&./test.xls&);
FileOutputStream fos = new FileOutputStream(file);
hwb.write(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
为你推荐:
其他类似问题
您可能关注的内容
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。博客分类:
1 工程所需jar包如下:
commons-codec-1.5.jar
commons-logging-1.1.jar
log4j-1.2.13.jar
junit-3.8.1.jar
poi-3.9-.jar
* 导出设备信息Excel
* @param form
和 HTTP 请求相关的表格对象
* @param resources 信息资源对象
* @param locale
本地化对象
* @param session
HTTP 会话对象
* @param request
HTTP 请求对象
* @param response
HTTP 响应对象
public String exportExcel(DynaBean form, MessageResources resources,
Locale locale, HttpSession session, HttpServletRequest request,
HttpServletResponse response) throws Exception{
int iLanguage = (locale.getLanguage().indexOf("en")&=0)?0:1;
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","filename="+java.net.URLEncoder.encode(resources.getMessage(locale, "device.details")+".xls","UTF-8"));
OutputStream sos = response.getOutputStream();
List&DeviceVO& deviceList = dao.getAllDevice();
HSSFWorkbook wb = new HSSFWorkbook();
Map&String, CellStyle& styles = createStyles(wb);
// 创建sheet页
Sheet sheet = wb.createSheet("Sheet");
PrintSetup printSetup = sheet.getPrintSetup();
printSetup.setLandscape(true);
sheet.setFitToPage(true);
sheet.setHorizontallyCenter(true);
*合并单元格的行或者列
sheet.addMergedRegion(CellRangeAddress.valueOf("$F$1:$H$1"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$M$1:$P$1"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$Q$1:$S$1"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$A$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$B$1:$B$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$C$1:$C$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$D$1:$D$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$E$1:$E$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$I$1:$I$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$J$1:$J$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$K$1:$K$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$L$1:$L$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$T$1:$T$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$U$1:$U$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$V$1:$V$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$W$1:$W$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$X$1:$X$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$Y$1:$Y$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$Z$1:$Z$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$AA$1:$AA$2"));
sheet.addMergedRegion(CellRangeAddress.valueOf("$AB$1:$AB$2"));
// 创建表头
Row headerRow = sheet.createRow(0);
headerRow.setHeightInPoints(30);
Cell headerC
headerCell = headerRow.createCell(0);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.number")); //设备编号
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(1);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.qrcode")); //设备二维码
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(2);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.customerbase")); //客户群
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(3);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.customertype")); //客户类别
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(4);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.customername")); //客户名称
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(5);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.area")); //设备区域
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(8);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.itemname")); //所属项目名称
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(9);
headerCell.setCellValue(resources.getMessage(locale, "device.category")); //设备类别
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(10);
headerCell.setCellValue(resources.getMessage(locale, "device.name")); //设备名称
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(11);
headerCell.setCellValue(resources.getMessage(locale, "device.no")); //设备信息编号
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(12);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.baseinfomation")); //设备基本信息
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(16);
headerCell.setCellValue(resources.getMessage(locale, "device.location")); //设备位置
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(19);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.enabledate")); //设备启用日期
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(20);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.backendload")); //后端负载
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(21);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.operationtips")); //操作提示
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(22);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.maintenancepeople")); //维护责任人
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(23);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.usetime")); //巡检时间
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(24);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.intervaltime")); //巡检下台设备时间间隔
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(25);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.patrolpath")); //巡检路径
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(26);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.enable")); //是否启用巡检路径
headerCell.setCellStyle(styles.get("header"));
headerCell = headerRow.createCell(27);
headerCell.setCellValue(resources.getMessage(locale, "device.export.excel.other")); //其他信息
headerCell.setCellStyle(styles.get("header"));
Row headerRowRegion = sheet.createRow(1);
headerRowRegion.setHeightInPoints(15);
Cell headerCellR
headerCellRegion = headerRowRegion.createCell(5);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.export.excel.province")); //省份
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(6);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.export.excel.region")); //市
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(7);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.export.excel.county")); //县/区
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(12);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.export.excel.brand")); //品牌
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(13);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.export.excel.model")); //型号
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(14);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.export.excel.capacity")); //容量
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(15);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.export.excel.systemtype")); //系统类型
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(16);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.build")); //楼号
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(17);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.floor")); //楼层
headerCellRegion.setCellStyle(styles.get("header"));
headerCellRegion = headerRowRegion.createCell(18);
headerCellRegion.setCellValue(resources.getMessage(locale, "device.room")); //房间号
headerCellRegion.setCellStyle(styles.get("header"));
for(int i=0;i&deviceList.size();i++){
DeviceVO device = deviceList.get(i);
Row cellRow = sheet.createRow(i + 2);
rowCell = cellRow.createCell(0);
rowCell.setCellValue(device.getDeviceId());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(1);
rowCell.setCellValue(device.getQrcode());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(2);
//判断是否是中文
if(iLanguage==1){
rowCell.setCellValue(device.getItemId().getCustomerBase().substring(device.getItemId().getCustomerBase().indexOf(":")+1,device.getItemId().getCustomerBase().length()));
}else if(iLanguage==0){ //判断是否是英文
rowCell.setCellValue(device.getItemId().getCustomerBase().substring(0,device.getItemId().getCustomerBase().indexOf(":")));
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(3);
//判断是否是中文
if(iLanguage==1){
rowCell.setCellValue(device.getItemId().getCustomerType().substring(device.getItemId().getCustomerType().indexOf(":")+1,device.getItemId().getCustomerType().length()));
}else if(iLanguage==0){ //判断是否是英文
rowCell.setCellValue(device.getItemId().getCustomerType().substring(0,device.getItemId().getCustomerType().indexOf(":")));
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(4);
rowCell.setCellValue(device.getItemId().getCustomerName());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(5);
rowCell.setCellValue(device.getItemId().getProvince());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(6);
rowCell.setCellValue(device.getItemId().getCity());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(7);
rowCell.setCellValue(device.getItemId().getCounty());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(8);
//判断是否是中文
if(iLanguage==1){
rowCell.setCellValue(device.getItemId().getItemName());
}else if(iLanguage==0){ //判断是否是英文
rowCell.setCellValue(device.getItemId().getForShort());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(9);
//判断是否是中文
if(iLanguage==1){
rowCell.setCellValue(device.getZequipId().getZequipGroup().getNameLoc());
}else if(iLanguage==0){ //判断是否是英文
rowCell.setCellValue(device.getZequipId().getZequipGroup().getNameEn());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(10);
rowCell.setCellValue(device.getDeviceName());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(11);
rowCell.setCellValue(device.getDeviceNo());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(12);
rowCell.setCellValue(device.getDeviceBrand());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(13);
rowCell.setCellValue(device.getEquipDriveId().getModel());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(14);
rowCell.setCellValue(device.getDeviceCapacity());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(15);
rowCell.setCellValue(device.getSystemType());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(16);
rowCell.setCellValue(device.getStairsNo());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(17);
rowCell.setCellValue(device.getFloor());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(18);
rowCell.setCellValue(device.getRoomNo());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(19);
rowCell.setCellValue(device.getEnableDate()!=null ? new SimpleDateFormat("yyyy-MM-dd").format(device.getEnableDate()) : "");
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(20);
rowCell.setCellValue(device.getBackendLoad());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(21);
rowCell.setCellValue(device.getOperationTips());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(22);
rowCell.setCellValue(device.getPersonId().getUserName());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(23);
rowCell.setCellValue(device.getInspecTime()+resources.getMessage(locale, "device.export.excel.minute"));
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(24);
rowCell.setCellValue(device.getIntervalTime()+resources.getMessage(locale, "device.export.excel.minute"));
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(25);
rowCell.setCellValue(device.getDevicePath());
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(26);
rowCell.setCellValue(device.getValidityNr() == 0 ? resources.getMessage(locale, "mmc.soft.person.disabled") : resources.getMessage(locale, "mmc.soft.person.enable"));
rowCell.setCellStyle(styles.get("cell"));
rowCell = cellRow.createCell(27);
rowCell.setCellValue(device.getOtherInfo() != null ? device.getOtherInfo() : "");
rowCell.setCellStyle(styles.get("cell"));
wb.write(sos);
sos.flush();
sos.close();
//excel样式
private Map&String, CellStyle& createStyles(Workbook wb)
Map&String, CellStyle& styles = new HashMap&String, CellStyle&();
Font titleFont = wb.createFont();
titleFont.setFontHeightInPoints((short) 18);
titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setFont(titleFont);
styles.put("title", style);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setWrapText(true);
styles.put("header", style);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setWrapText(true);
styles.put("cell", style);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
styles.put("formula", style);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
styles.put("formula_2", style);
浏览 23155
jie_bosshr
浏览: 95941 次
来自: 西安
poi生成excel文件,之前也用过,就是感觉代码好多啊。后来 ...
楼主的代码貌似不行哎,登陆就出现错误了,请问是否有可以模拟登陆 ...
atoi这个方法怎么没有定义?
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 poi导出excel大数据 的文章

 

随机推荐