private void createStyles(HSSFWorkbook workBook, HSSFSheet workSheet) { /*Font bold = workBook.createFont(); bold.setBoldweight(Font.BOLDWEIGHT_BOLD); bold.setFontHeightInPoints((short) 10); bold.setColor(Font.COLOR_RED);*/ HSSFFont hssfFont = workBook.createFont(); hssfFont.setBoldweight(Font.BOLDWEIGHT_BOLD); hssfFont.setColor(Font.COLOR_RED); boldStyle = workBook.createCellStyle(); boldStyle.setBorderBottom(CellStyle.BORDER_THIN); boldStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); boldStyle.setFont(hssfFont); boldStyle.setFillBackgroundColor(HSSFColor.BLUE.index); defaultFont = workBook.createFont(); defaultFont.setFontHeightInPoints((short) 10); defaultFont.setFontName("Arial"); defaultFont.setColor(IndexedColors.BLACK.getIndex()); defaultFont.setBoldweight(Font.BOLDWEIGHT_BOLD); defaultFont.setItalic(true); newStyle = workBook.createCellStyle(); // newStyle.setFillBackgroundColor(IndexedColors.DARK_GREEN.getIndex()); // newStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); newStyle.setAlignment(CellStyle.ALIGN_CENTER); newStyle.setFont(defaultFont); /* hssfCellStyle = workBook.createCellStyle(); hssfCellStyle.setBorderBottom(CellStyle.BORDER_THIN); hssfCellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); hssfCellStyle.setFont(bold);*/ }
public HSSFCellStyle createLastCellStyle(boolean white) { HSSFCellStyle style = workbook.createCellStyle(); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(HSSFColor.DARK_BLUE.index); style.setLeftBorderColor(HSSFColor.DARK_BLUE.index); style.setBottomBorderColor(HSSFColor.DARK_BLUE.index); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); if (white) { style.setFillBackgroundColor(HSSFColor.WHITE.index); style.setFillForegroundColor(HSSFColor.WHITE.index); } else { style.setFillBackgroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); style.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); } HSSFFont font = workbook.createFont(); font.setFontName("Arial"); font.setFontHeightInPoints((short) 12); style.setFont(font); return style; }
/** * 摘要: @说明:Excel样式 @创建:作者:yxy 创建时间:2011-8-17 * * @param workBook * @param cellStyle 样式模型 * @return @修改历史: [序号](yxy 2011-8-17)<修改说明> */ public static HSSFCellStyle getNewStyle(HSSFWorkbook workBook, CellStyle cellStyle) { HSSFCellStyle style = workBook.createCellStyle(); // 对齐方式 style.setAlignment(cellStyle.getAlignment()); style.setVerticalAlignment(cellStyle.getVAlignment()); // 设置背景颜色 // 最好的设置Pattern style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // 单元格背景的显示模式 style.setFillForegroundColor(cellStyle.getColor()); // 单元格背景的显示模式. // 设置边框 style.setBorderBottom(cellStyle.getBorderBottom()); // 下边框 style.setBorderLeft(cellStyle.getBorderLeft()); // 左边框 style.setBorderTop(cellStyle.getBorderTop()); // 上边框 style.setBorderRight(cellStyle.getBorderRight()); // 右边框 // 设置边框颜色 style.setBottomBorderColor(cellStyle.getBottomBorderColor()); style.setTopBorderColor(cellStyle.getTopBorderColor()); style.setLeftBorderColor(cellStyle.getLeftBorderColor()); style.setRightBorderColor(cellStyle.getRightBorderColor()); // 设置自动换行 style.setWrapText(cellStyle.getWrapText()); style.setHidden(cellStyle.getHidden()); // 数据格式 style.setDataFormat(cellStyle.getDataFormate()); style.setLocked(cellStyle.getLocked()); // 文本旋转 请注意,这里的Rotation取值是从-90到90,而不是0-180度 style.setRotation(cellStyle.getRotation()); // 文本缩进 style.setIndention(cellStyle.getIndention()); return style; }
public void applyTo(HSSFCellStyle style, HSSFWorkbook workbook) { style.setAlignment(this.alignment); style.setBorderBottom(this.borderBottom); style.setBorderLeft(this.borderLeft); style.setBorderRight(this.borderRight); style.setBorderTop(this.borderTop); style.setBottomBorderColor(this.bottomBorderColor); style.setDataFormat(this.dataFormat); style.setFillPattern(this.fillPattern); style.setFillForegroundColor(this.fillForegroundColor); style.setFillBackgroundColor(this.fillBackgroundColor); style.setFont(workbook.getFontAt(this.fontIndex)); style.setHidden(this.hidden); style.setIndention(this.indention); style.setLeftBorderColor(this.leftBorderColor); style.setLocked(this.locked); style.setRightBorderColor(this.rightBorderColor); style.setRotation(this.rotation); style.setTopBorderColor(this.topBorderColor); style.setVerticalAlignment(this.verticalAlignment); style.setWrapText(this.wrapText); }
private void setBorder(HSSFCellStyle cellStyle, int _f, int mode) { // 0=bottom, 1=top, 2=left, 3=right,4=all if (mode != 0) cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); if (mode != 2 && mode != 4) cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); if (mode != 3 && mode != 4) cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); if (mode != 1) cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); if (_f == 1) cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle.setWrapText(true); }
private void setBorder(HSSFCellStyle cellStyle, int _f) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); if (_f == 1) cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle.setWrapText(true); }
private void initMessageStyle() { messageStyle = wb.createCellStyle(); messageStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); messageStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); messageStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); messageStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); messageStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); messageStyle.setWrapText(true); messageStyle.setFont(normalFont); }
private void initKeyStyle() { keyStyle = wb.createCellStyle(); keyStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); keyStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); keyStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); keyStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); keyStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); keyStyle.setWrapText(true); keyStyle.setFont(normalFont); }
public static HSSFCellStyle rowStyle2(final HSSFSheet sheet) { HSSFCellStyle style = sheet.getWorkbook().createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); style.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); return style; }
private void initEmptyStyle() { emptyStyle = wb.createCellStyle(); emptyStyle.setFillForegroundColor(HSSFColor.RED.index); emptyStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); emptyStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); emptyStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); emptyStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); emptyStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); emptyStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); }
// 默认cell样式 public HSSFCellStyle getDefaultStyle(HSSFWorkbook wb) { HSSFCellStyle style = wb.createCellStyle(); // 设置边框样式 style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); return style; }
private void initNormalStyle() { normalStyle = wb.createCellStyle(); normalStyle.setFillForegroundColor(HSSFColor.WHITE.index); normalStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); normalStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); normalStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); normalStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); normalStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); normalStyle.setWrapText(true); normalStyle.setFont(normalFont); }
private void initChangedOrEmptyStyle() { changedOrEmptyStyle = wb.createCellStyle(); changedOrEmptyStyle.setFillForegroundColor(HSSFColor.PINK.index); changedOrEmptyStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); changedOrEmptyStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); changedOrEmptyStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); changedOrEmptyStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); changedOrEmptyStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); changedOrEmptyStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); changedOrEmptyStyle.setWrapText(true); changedOrEmptyStyle.setFont(normalFont); }
public void decorateRowWithBoldCellBlueBackground(int cellId, HSSFRow row, Object value) { HSSFCellStyle boldStyleBlueBground = workbook.createCellStyle(); boldStyleBlueBground.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); boldStyleBlueBground.setFont(boldFont); boldStyleBlueBground.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); boldStyleBlueBground.setFillForegroundColor(new HSSFColor.LIGHT_TURQUOISE().getIndex()); boldStyleBlueBground.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); boldStyleBlueBground.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); boldStyleBlueBground.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); boldStyleBlueBground.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); this.decorateRowWithCell((short) cellId, row, value, boldStyleBlueBground); }
private HSSFCellStyle getHeaderStyle2( final HSSFWorkbook workbook, final boolean shouldRed, final boolean shouldBackground, final boolean shouldSmall, final boolean end, final boolean changeover, final Font font) { HSSFCellStyle style = workbook.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setWrapText(true); font.setFontName(HSSFFont.FONT_ARIAL); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 9); font.setColor(HSSFFont.COLOR_NORMAL); style.setFont(font); if (shouldRed) { font.setColor(HSSFFont.COLOR_RED); style.setFont(font); } if (shouldBackground) { if (changeover) { style.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index); } else { style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); } style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); } if (shouldSmall) { font.setFontHeightInPoints((short) 7); style.setFont(font); } if (end) { style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); } return style; }
/** * 文本框的样式 * * @param wb * @return */ private HSSFCellStyle getTextStyle(HSSFWorkbook wb) { if (textStyle == null) { textStyle = wb.createCellStyle(); textStyle.setFillForegroundColor(HSSFColor.WHITE.index); textStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); textStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); textStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); textStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); textStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); textStyle.setBottomBorderColor(HSSFColor.BLACK.index); textStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); textStyle.setWrapText(true); } return textStyle; }
/** * Builds the column headers * * @param worksheet * @param startRowIndex starting row offset * @param startColIndex starting column offset */ public static void buildHeaders( HSSFSheet worksheet, int startRowIndex, int startColIndex, List<Production> datasource) { // Create font style for the headers Font font = worksheet.getWorkbook().createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); // Create cell style for the headers HSSFCellStyle headerCellStyle = worksheet.getWorkbook().createCellStyle(); headerCellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); headerCellStyle.setFillPattern(CellStyle.FINE_DOTS); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); headerCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); headerCellStyle.setWrapText(true); headerCellStyle.setFont(font); headerCellStyle.setBorderBottom(CellStyle.BORDER_THIN); // Create the column headers HSSFRow rowHeader = worksheet.createRow((short) startRowIndex + 2); rowHeader.setHeight((short) 500); HSSFCell cell0 = rowHeader.createCell(startColIndex + 0); cell0.setCellValue("Shift"); cell0.setCellStyle(headerCellStyle); int dyn = 1; List<Compensation> compensations = datasource.get(0).getCompensations(); for (Compensation compensation : compensations) { HSSFCell cellc1 = rowHeader.createCell(startColIndex + 0 + dyn); cellc1.setCellValue(compensation.getElectricmeter().getName()); cellc1.setCellStyle(headerCellStyle); dyn++; HSSFCell cellc2 = rowHeader.createCell(startColIndex + 0 + dyn); cellc2.setCellValue(compensation.getElectricmeter().getName() + "\nkW·h"); cellc2.setCellStyle(headerCellStyle); dyn++; } HSSFCell cell5 = rowHeader.createCell(startColIndex + 0 + dyn + 0); cell5.setCellValue("580 İnd/Reak"); cell5.setCellStyle(headerCellStyle); HSSFCell cell6 = rowHeader.createCell(startColIndex + 0 + dyn + 1); cell6.setCellValue("880 Kap/Reak"); cell6.setCellStyle(headerCellStyle); }
private void initContentCellStyle() { // 生成并设置另一个样式 style2 = workbook.createCellStyle(); style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setBorderLeft(HSSFCellStyle.BORDER_THIN); style2.setBorderRight(HSSFCellStyle.BORDER_THIN); style2.setBorderTop(HSSFCellStyle.BORDER_THIN); style2.setAlignment(HSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 生成另一个字体 HSSFFont font2 = workbook.createFont(); font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // 把字体应用到当前的样式 style2.setFont(font2); }
private void initHeadCellStyle() { style = workbook.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(HSSFColor.SKY_BLUE.index); style.setFillPattern(HSSFCellStyle.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); // 生成一个字体 HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 把字体应用到当前的样式 style.setFont(font); }
protected HSSFCellStyle createHeaderCellStyle() { HSSFCellStyle style = workbook.createCellStyle(); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(HSSFColor.DARK_BLUE.index); style.setLeftBorderColor(HSSFColor.DARK_BLUE.index); style.setTopBorderColor(HSSFColor.DARK_BLUE.index); style.setBottomBorderColor(HSSFColor.DARK_BLUE.index); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFillBackgroundColor(HSSFColor.DARK_BLUE.index); style.setFillForegroundColor(HSSFColor.DARK_BLUE.index); HSSFFont font = workbook.createFont(); font.setFontName("Arial"); font.setFontHeightInPoints((short) 12); font.setColor(HSSFColor.WHITE.index); style.setFont(font); return style; }
private HSSFCellStyle getHeaderStyleChangeoverEnd(final HSSFWorkbook workbook, final Font font) { HSSFCellStyle style = workbook.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setWrapText(true); font.setFontName(HSSFFont.FONT_ARIAL); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 9); style.setFont(font); style.setFillForegroundColor(HSSFColor.SKY_BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); return style; }
private static void buildHeaders(HSSFSheet worksheet, int startRowIndex, int startColIndex) { // Header字体 Font font = worksheet.getWorkbook().createFont(); font.setBoldweight((short) Font.BOLDWEIGHT_BOLD); // font.setColor(HSSFColor.BLUE.index);//设置字体颜色 // 单元格样式 HSSFCellStyle headerCellStyle = worksheet.getWorkbook().createCellStyle(); // headerCellStyle.setFillForegroundColor(HSSFColor.GREY_80_PERCENT.index);//前景色 // headerCellStyle.setFillBackgroundColor(HSSFColor.GREY_80_PERCENT.index);//背景色 // headerCellStyle.setFillPattern(CellStyle.FINE_DOTS); //设置填充方式 headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); headerCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); headerCellStyle.setWrapText(true); headerCellStyle.setFont(font); headerCellStyle.setBorderBottom(CellStyle.BORDER_THIN); headerCellStyle.setBorderLeft(CellStyle.BORDER_THIN); headerCellStyle.setBorderRight(CellStyle.BORDER_THIN); headerCellStyle.setBorderTop(CellStyle.BORDER_THIN); // 创建字段标题 HSSFRow rowHeader = worksheet.createRow((short) startRowIndex + 2); rowHeader.setHeight((short) 500); HSSFCell cell1 = rowHeader.createCell(startColIndex + 0); cell1.setCellValue("学号"); cell1.setCellStyle(headerCellStyle); HSSFCell cell2 = rowHeader.createCell(startColIndex + 1); cell2.setCellValue("姓名"); cell2.setCellStyle(headerCellStyle); HSSFCell cell3 = rowHeader.createCell(startColIndex + 2); cell3.setCellValue("得分"); cell3.setCellStyle(headerCellStyle); }
/** * Создает новый стиль в документе Excel который полностью копирует свойства некоторого исходного * стиля этого же документа. Данный метод используется для того чтобы в последствии поменять в * новом стиле один или несколько свойств не затрагивая при этом свойства исходного стиля. * * @param wb документ Excel. * @param src стиль ячейки взятый в качестве шаблона. * @return созданная копия исходного стиля в этом же документе. */ public static HSSFCellStyle copyStyle(final HSSFWorkbook wb, final HSSFCellStyle src) { final HSSFCellStyle dst = wb.createCellStyle(); dst.setAlignment(src.getAlignment()); dst.setBorderBottom(src.getBorderBottom()); dst.setBorderLeft(src.getBorderLeft()); dst.setBorderRight(src.getBorderRight()); dst.setBorderTop(src.getBorderTop()); dst.setBottomBorderColor(src.getBottomBorderColor()); dst.setDataFormat(src.getDataFormat()); dst.setFillForegroundColor(src.getFillForegroundColor()); dst.setFillBackgroundColor(src.getFillBackgroundColor()); dst.setFillPattern(src.getFillPattern()); dst.setFont(src.getFont(wb)); dst.setHidden(src.getHidden()); dst.setIndention(src.getIndention()); dst.setLeftBorderColor(src.getLeftBorderColor()); dst.setLocked(src.getLocked()); dst.setRightBorderColor(src.getRightBorderColor()); dst.setRotation(src.getRotation()); dst.setTopBorderColor(src.getTopBorderColor()); dst.setVerticalAlignment(src.getVerticalAlignment()); dst.setWrapText(src.getWrapText()); return dst; }
private HSSFCellStyle createMatrixCellStyle( HSSFWorkbook workbook, HSSFCellStyle matrixHeaderTemplateCellStyle, boolean top, boolean right, boolean bottom, boolean left) { HSSFCellStyle cellStyle = POIUtils.copyCellStyle(workbook, matrixHeaderTemplateCellStyle); if (top) { cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); } if (right) { cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); } if (bottom) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); } if (left) { cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); } return cellStyle; }
public void generateExcel(OutputStream out, XLSCallBack<T> xlscaCallBack) throws RuntimeException, IOException { HSSFWorkbook workbook = new HSSFWorkbook(); // create a sheet with specified name HSSFSheet sheet = workbook.createSheet(xlscaCallBack.getSheetName()); for (int i = 0; i < xlscaCallBack.getColumnWidth().length; i++) { sheet.setColumnWidth(i, xlscaCallBack.getColumnWidth()[i] * 256); } // create a title for sheet title sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, xlscaCallBack.getHeaders().length - 1)); HSSFCellStyle titleCellStyle = workbook.createCellStyle(); // create titleCellStyle for cell titleCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFFont titleFont = workbook.createFont(); // set font titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); titleFont.setFontName("宋体"); titleFont.setFontHeight((short) (240)); titleFont.setColor(HSSFColor.AUTOMATIC.index); titleCellStyle.setFont(titleFont); titleCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // set border titleCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // set background titleCellStyle.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index); titleCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleCellStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); HSSFRow title = sheet.createRow(0); title.setHeight((short) 300); for (int i = 0; i < xlscaCallBack.getHeaders().length; i++) { // create tytle for title HSSFCell cell = title.createCell(i); cell.setCellValue(xlscaCallBack.getTitle()); cell.setCellStyle(titleCellStyle); } HSSFCellStyle headerCellStyle = workbook.createCellStyle(); // create headerCellStyle for cell headerCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFFont headerFont = workbook.createFont(); // set font headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerFont.setFontName("幼圆"); headerFont.setColor(HSSFColor.AUTOMATIC.index); headerCellStyle.setFont(headerFont); headerCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // set border headerCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headerCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headerCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headerCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // set background headerCellStyle.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index); headerCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headerCellStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); HSSFRow header = sheet.createRow(1); for (int i = 0; i < xlscaCallBack.getHeaders().length; i++) { // create tytle for header HSSFCell cell = header.createCell(i); cell.setCellValue(xlscaCallBack.getHeaders()[i]); cell.setCellStyle(headerCellStyle); } HSSFCellStyle rowCellStyle = workbook.createCellStyle(); // create headerCellStyle for cell rowCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFFont rowFont = workbook.createFont(); // set font rowFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); rowFont.setFontName("幼圆"); rowFont.setColor(HSSFColor.AUTOMATIC.index); rowCellStyle.setFont(rowFont); rowCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // set border rowCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); rowCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); rowCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); for (int i = 0; i < lists.size(); i++) { HSSFRow row = sheet.createRow(i + 2); String values[] = xlscaCallBack.getValue(lists.get(i)); for (int j = 0; j < values.length; j++) { HSSFCell cell = row.createCell(j); cell.setCellValue(values[j]); cell.setCellStyle(rowCellStyle); } } HSSFCellStyle bottomCellStyle = workbook.createCellStyle(); // create titleCellStyle for cell bottomCellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); HSSFFont bottomFont = workbook.createFont(); // set font bottomFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); bottomFont.setFontName("幼圆"); bottomFont.setColor(HSSFColor.AUTOMATIC.index); bottomCellStyle.setFont(bottomFont); bottomCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); // set border bottomCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); bottomCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); bottomCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); bottomCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // set background bottomCellStyle.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index); bottomCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); bottomCellStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); sheet.addMergedRegion( new CellRangeAddress( lists.size() + 2, lists.size() + 2, 0, xlscaCallBack.getHeaders().length - 1)); // creaet bootom for xls HSSFRow bottomRow = sheet.createRow(lists.size() + 2); for (int i = 0; i < xlscaCallBack.getHeaders().length; i++) { // create tytle for title HSSFCell cell = bottomRow.createCell(i); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); cell.setCellValue("共计导出 " + lists.size() + " 条记录 ,导出日期:" + sf.format(new Date())); cell.setCellStyle(bottomCellStyle); } try { workbook.write(out); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("create Excel failed due to some unkonw reasion~"); } }
public void exportExcel( String headline, String title, String[] headers, List<Object[]> dataset, OutputStream out, short[] width) { // 声明一个工作薄 HSSFWorkbook workbook = new HSSFWorkbook(); // 生成一个表格 HSSFSheet sheet = workbook.createSheet(title); // 设置表格默认列宽度为15个字节 sheet.setDefaultColumnWidth((short) 15); // 生成一个样式 HSSFCellStyle style = workbook.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); style.setFillPattern(HSSFCellStyle.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); // 生成一个字体 HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 把字体应用到当前的样式 style.setFont(font); // 生成并设置另一个样式 HSSFCellStyle style2 = workbook.createCellStyle(); style2.setFillForegroundColor(HSSFColor.WHITE.index); style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setBorderLeft(HSSFCellStyle.BORDER_THIN); style2.setBorderRight(HSSFCellStyle.BORDER_THIN); style2.setBorderTop(HSSFCellStyle.BORDER_THIN); style2.setAlignment(HSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 生成另一个字体 HSSFFont font2 = workbook.createFont(); font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // 把字体应用到当前的样式 style2.setFont(font2); // 产生表格标题行 HSSFRow row = sheet.createRow(0); if (row != null) { HSSFCell cell = row.createCell(0); HSSFFont f = workbook.createFont(); f.setColor(HSSFColor.DARK_BLUE.index); f.setFontHeightInPoints((short) 24); f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 把字体应用到当前的样式 HSSFCellStyle s = workbook.createCellStyle(); s.setAlignment(HSSFCellStyle.ALIGN_CENTER); s.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); s.setFont(f); cell.setCellStyle(s); cell.setCellValue(headline); } sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) (headers.length - 1))); row = sheet.createRow(1); for (short i = 0; i < headers.length; i++) { HSSFCell cell = row.createCell(i); cell.setCellStyle(style); HSSFRichTextString text = new HSSFRichTextString(headers[i]); cell.setCellValue(text); } for (int j = 0; j < dataset.size(); j++) { row = sheet.createRow(j + 2); for (short i = 0; i < dataset.get(j).length; i++) { HSSFCell cell = row.createCell(i); cell.setCellStyle(style2); HSSFRichTextString richString = new HSSFRichTextString(String.valueOf(dataset.get(j)[i]).replace("null", "")); // HSSFFont font3 = workbook.createFont(); // font3.setColor(HSSFColor.BLACK.index); // richString.applyFont(font3); cell.setCellValue(richString); } } if (width != null) { for (short i = 0; i < width.length; i++) { sheet.setColumnWidth(i, width[i]); } } try { workbook.write(out); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void exportJgjExcel( String title, List<String[]> header, List<Object[]> dataset, OutputStream out, short[] width, List<int[]> merge) { // 声明一个工作薄 HSSFWorkbook workbook = new HSSFWorkbook(); // 生成一个表格 HSSFSheet sheet = workbook.createSheet(title); // 设置表格默认列宽度为15个字节 sheet.setDefaultColumnWidth((short) 15); // 生成一个样式 HSSFCellStyle style = workbook.createCellStyle(); // 设置这些样式 style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); style.setFillPattern(HSSFCellStyle.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); // 生成一个字体 HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 把字体应用到当前的样式 style.setFont(font); // 生成并设置另一个样式 HSSFCellStyle style2 = workbook.createCellStyle(); style2.setFillForegroundColor(HSSFColor.WHITE.index); style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setBorderLeft(HSSFCellStyle.BORDER_THIN); style2.setBorderRight(HSSFCellStyle.BORDER_THIN); style2.setBorderTop(HSSFCellStyle.BORDER_THIN); style2.setAlignment(HSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 生成另一个字体 HSSFFont font2 = workbook.createFont(); font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // 把字体应用到当前的样式 style2.setFont(font2); // 产生表格标题行 HSSFRow row = sheet.createRow(0); for (int i = 0; i < header.size(); i++) { row = sheet.createRow(i); for (int m = 0; m < header.get(i).length; m++) { HSSFCell cell = row.createCell(m); cell.setCellStyle(style); String headValue = header.get(i)[m]; // HSSFRichTextString text = new HSSFRichTextString(header.get(i)[m]); cell.setCellValue(headValue); } } if (merge != null && merge.size() > 0) { for (int m = 0; m < merge.size(); m++) { sheet.addMergedRegion( new CellRangeAddress( merge.get(m)[0], merge.get(m)[1], merge.get(m)[2], merge.get(m)[3])); // 合并行 } } // sheet.addMergedRegion(new CellRangeAddress(0,0,9,10)); // sheet.addMergedRegion(new CellRangeAddress(0,0,11,12)); for (int j = 0; j < dataset.size(); j++) { row = sheet.createRow(j + header.size()); for (short i = 0; i < dataset.get(j).length; i++) { HSSFCell cell = row.createCell(i); cell.setCellStyle(style2); HSSFRichTextString richString = new HSSFRichTextString(String.valueOf(dataset.get(j)[i]).replace("null", "")); // HSSFFont font3 = workbook.createFont(); // font3.setColor(HSSFColor.BLACK.index); // richString.applyFont(font3); cell.setCellValue(richString); } } if (width != null) { for (short i = 0; i < width.length; i++) { sheet.setColumnWidth(i, width[i]); } } try { workbook.write(out); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
protected Map<Short, HSSFCellStyle> applyStyles(final Report report, final HSSFWorkbook wb) { final StylePalette palette = report.getPalette(); final Map<Short, HSSFCellStyle> styles = new HashMap<Short, HSSFCellStyle>(); if (report.getTemplate() != null) { for (final short styleIndex : palette.getStyles().keySet()) { final HSSFCellStyle style = wb.getCellStyleAt(styleIndex); if (style == null) throw new RuntimeException( "Inconsistent report template. Style not found: " + styleIndex); styles.put(styleIndex, style); } return styles; } if (palette.getColors().size() > PaletteRecord.STANDARD_PALETTE_SIZE) throw new RuntimeException("too many colors on report"); final HSSFPalette pal = wb.getCustomPalette(); for (final Color color : palette.getColors().values()) { pal.setColorAtIndex(color.getId(), color.getRed(), color.getGreen(), color.getBlue()); } final Map<Short, HSSFFont> fonts = new HashMap<Short, HSSFFont>(); final HSSFDataFormat formatter = wb.createDataFormat(); for (final Font font : palette.getFonts().values()) { final HSSFFont f = POIUtils.ensureFontExists(wb, font); fonts.put(font.getId(), f); } for (final CellStyle style : palette.getStyles().values()) { final short bbc = style.getBottomBorderColor() != null ? style.getBottomBorderColor().getId() : 0; final short fbc = style.getFillBackgroundColor() != null ? style.getFillBackgroundColor().getId() : 0; final short ffc = style.getFillForegroundColor() != null ? style.getFillForegroundColor().getId() : 0; final short lbc = style.getLeftBorderColor() != null ? style.getLeftBorderColor().getId() : 0; final short rbc = style.getRightBorderColor() != null ? style.getRightBorderColor().getId() : 0; final short tbc = style.getTopBorderColor() != null ? style.getTopBorderColor().getId() : 0; final HSSFCellStyle s = wb.createCellStyle(); s.setAlignment(style.getAlignment()); s.setBorderBottom(style.getBorderBottom()); s.setBorderLeft(style.getBorderLeft()); s.setBorderRight(style.getBorderRight()); s.setBorderTop(style.getBorderTop()); s.setBottomBorderColor(bbc); s.setDataFormat(formatter.getFormat(style.getDataFormat())); s.setFillBackgroundColor(fbc); s.setFillForegroundColor(ffc); s.setFillPattern(style.getFillPattern()); s.setHidden(style.isHidden()); s.setIndention(style.getIndention()); s.setLeftBorderColor(lbc); s.setLocked(style.isLocked()); s.setRightBorderColor(rbc); s.setRotation(style.getRotation()); s.setTopBorderColor(tbc); s.setVerticalAlignment(style.getVerticalAlignment()); s.setWrapText(style.isWrapText()); s.setFont(fonts.get(style.getFont().getId())); styles.put(style.getId(), s); } return styles; }
// 导出报表到 excel public void toExcel() throws Exception { String date = Common.getSystemDate(); // 定义excel以及sheet HSSFWorkbook workBook = new HSSFWorkbook(); HSSFSheet sheet = workBook.createSheet(date + "学工部设备表"); // header sheet.setColumnWidth((short) 0, (short) (8 * 256)); sheet.setColumnWidth((short) 1, (short) (20 * 256)); sheet.setColumnWidth((short) 2, (short) (20 * 256)); sheet.setColumnWidth((short) 3, (short) (16 * 256)); sheet.setColumnWidth((short) 4, (short) (20 * 256)); sheet.setColumnWidth((short) 5, (short) (20 * 256)); sheet.setColumnWidth((short) 6, (short) (20 * 256)); sheet.setColumnWidth((short) 7, (short) (16 * 256)); sheet.setColumnWidth((short) 8, (short) (20 * 256)); sheet.setColumnWidth((short) 9, (short) (20 * 256)); sheet.setColumnWidth((short) 10, (short) (20 * 256)); sheet.setColumnWidth((short) 11, (short) (20 * 256)); HSSFRow titleRow = sheet.createRow((short) 0); HSSFCell titleCell = titleRow.createCell((short) 0); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("重庆邮电大学学工部设备表"); // 设置表头样式 HSSFCellStyle titleStyle = workBook.createCellStyle(); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 表头字体 HSSFFont titleFont = workBook.createFont(); titleFont.setFontHeightInPoints((short) 16); titleFont.setFontName("黑体"); titleStyle.setFont(titleFont); // 表头边框 titleStyle.setBorderBottom(CellStyle.BORDER_THIN); // titleStyle.setBorderLeft(CellStyle.BORDER_THIN); titleStyle.setBorderRight(CellStyle.BORDER_THIN); // titleStyle.setBorderTop(CellStyle.BORDER_THIN); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 9); titleCell.setCellStyle(titleStyle); // 设置单元格边框 titleRow = sheet.createRow((short) 1); titleCell = titleRow.createCell((short) 0); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 1); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 2); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 3); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 4); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 5); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 6); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 7); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 8); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 9); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 10); titleCell.setCellStyle(titleStyle); titleCell = titleRow.createCell((short) 11); titleCell.setCellStyle(titleStyle); // 合并单元格 0行0列 1行9列 sheet.addMergedRegion(new Region(0, (short) 0, 1, (short) 11)); // 内容样式 HSSFCellStyle contentStyle = workBook.createCellStyle(); contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 内容字体 HSSFFont contentFont = workBook.createFont(); contentFont.setFontHeightInPoints((short) 11); contentFont.setFontName("宋体"); contentStyle.setFont(contentFont); contentStyle.setBorderBottom(CellStyle.BORDER_THIN); contentStyle.setBorderRight(CellStyle.BORDER_THIN); // contentStyle.setBorderLeft(CellStyle.BORDER_THIN); // contentStyle.setBorderTop(CellStyle.BORDER_THIN); // 第二行表头 titleRow = sheet.createRow((short) 2); titleCell = titleRow.createCell((short) 0); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("编号"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 1); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("名称"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 2); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("设备价值(元)"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 3); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("申请部门"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 4); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("申请人"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 5); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("购买时间"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 6); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("购买地点"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 7); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("设备状态"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 8); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("生产厂商"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 9); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("使用部门"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 10); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("使用人"); titleCell.setCellStyle(contentStyle); List<Equipment> equipmentListtemp = new ArrayList<Equipment>(); equipmentListtemp = this.equipmentService.getEquipmentBycondtion("where 1=1"); int i = 0; Double totalMoney = 0d; String totalString = ""; for (i = 0; i < equipmentListtemp.size(); ++i) { titleRow = sheet.createRow((short) (i + 3)); // 第一列 编号 titleCell = titleRow.createCell((short) 0); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getEquipmentcode() != null) titleCell.setCellValue(equipmentListtemp.get(i).getEquipmentcode()); else titleCell.setCellValue(i + 1); titleCell.setCellStyle(contentStyle); // 第二列 名称 titleCell = titleRow.createCell((short) 1); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getName() != null) titleCell.setCellValue(equipmentListtemp.get(i).getName()); else titleCell.setCellValue(""); titleCell.setCellStyle(contentStyle); // 第三列 设备价值 titleCell = titleRow.createCell((short) 2); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getValueof().toString() != null) { titleCell.setCellValue(equipmentListtemp.get(i).getValueof().toString()); totalMoney += equipmentListtemp.get(i).getValueof(); } else { titleCell.setCellValue("0"); totalMoney += 0; } titleCell.setCellStyle(contentStyle); // 第四列 申请部门 titleCell = titleRow.createCell((short) 3); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); String officeIdTemp = equipmentListtemp.get(i).getDepartment(); if (officeIdTemp != null) { Studentoffice studentofficetemp = this.studentofficeService.findById(officeIdTemp); if (studentofficetemp != null) { titleCell.setCellValue(studentofficetemp.getName()); } } else { titleCell.setCellValue("请检查办公室"); } titleCell.setCellStyle(contentStyle); // 第五列 申请人 titleCell = titleRow.createCell((short) 4); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getBuyers() != null) titleCell.setCellValue(equipmentListtemp.get(i).getBuyers()); else titleCell.setCellValue(""); titleCell.setCellStyle(contentStyle); // 第六列 购买时间 titleCell = titleRow.createCell((short) 5); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getPurchasetime() != null) titleCell.setCellValue(equipmentListtemp.get(i).getPurchasetime().trim()); else titleCell.setCellValue(""); titleCell.setCellStyle(contentStyle); // 第七列 购买地点 titleCell = titleRow.createCell((short) 6); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getAddress() != null) titleCell.setCellValue(equipmentListtemp.get(i).getAddress()); else titleCell.setCellValue("请检查岗位名称"); titleCell.setCellStyle(contentStyle); // 第八列 设备状态 titleCell = titleRow.createCell((short) 7); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getStates() == 1) { titleCell.setCellValue("正常"); } else titleCell.setCellValue("报废"); titleCell.setCellStyle(contentStyle); // 第九列 生产厂商 titleCell = titleRow.createCell((short) 8); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); if (equipmentListtemp.get(i).getFactory() != null) { titleCell.setCellValue(equipmentListtemp.get(i).getFactory()); } else titleCell.setCellValue(""); titleCell.setCellStyle(contentStyle); // 第十列 使用部门 titleCell = titleRow.createCell((short) 9); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); Studentoffice Studentofficenow = new Studentoffice(); List<Equipmentdepartment> equipmentdepartmentlisttemp = this.equipmentDepartmentService.findByEquipmentId(equipmentListtemp.get(i).getId()); Equipmentdepartment Equipmentdepartmentnow = new Equipmentdepartment(); for (int j = 0; j < equipmentdepartmentlisttemp.size(); j++) { if (equipmentdepartmentlisttemp.get(j).getFlowouttime() == null || equipmentdepartmentlisttemp.get(j).getFlowouttime().length() == 0) { Equipmentdepartmentnow = equipmentdepartmentlisttemp.get(j); Studentofficenow = this.studentofficeService.findById( equipmentdepartmentlisttemp.get(j).getDepartment()); break; } } if (Studentofficenow.getName() != null) { titleCell.setCellValue(Studentofficenow.getName()); } else titleCell.setCellValue(""); titleCell.setCellStyle(contentStyle); // 第十一列 使用人 titleCell = titleRow.createCell((short) 10); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); Officeteacher officeteachernow = new Officeteacher(); if (Equipmentdepartmentnow != null) { if (Equipmentdepartmentnow != null) { List<Equipmentuser> equipmentUserNowList = this.equipmentuserService.findByEquipmentdepId(Equipmentdepartmentnow.getId()); for (int j = 0; j < equipmentUserNowList.size(); j++) { if (equipmentUserNowList.get(j).getFlowouttime2() == null || equipmentUserNowList.get(j).getFlowouttime2().length() == 0) { officeteachernow = this.officeteacherService.findById( equipmentUserNowList.get(j).getEquipmentuser()); break; } } } } if (officeteachernow != null) { if (officeteachernow.getTeacher() != null) { if (officeteachernow.getTeacher().getName() != null) { titleCell.setCellValue(officeteachernow.getTeacher().getName()); } } } else titleCell.setCellValue(""); titleCell.setCellStyle(contentStyle); } titleRow = sheet.createRow((short) (i + 3)); titleCell = titleRow.createCell((short) 0); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("合计"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 1); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 2); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellStyle(contentStyle); titleCell.setCellValue("¥" + totalMoney + "元"); titleCell = titleRow.createCell((short) 11); titleCell.setCellStyle(contentStyle); // 设置单元格边框 titleRow = sheet.createRow((short) (i + 4)); titleCell = titleRow.createCell((short) 0); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 1); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 2); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 3); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 4); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 5); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 6); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 7); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 8); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 9); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 10); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 11); titleCell.setCellStyle(contentStyle); sheet.addMergedRegion(new Region((i + 3), (short) 0, (i + 4), (short) 1)); sheet.addMergedRegion(new Region((i + 3), (short) 2, (i + 4), (short) 11)); // 设置单元格边框 titleRow = sheet.createRow((short) (i + 5)); titleCell = titleRow.createCell((short) 0); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); titleCell.setCellValue("大写"); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 1); titleCell.setCellStyle(contentStyle); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 2); titleCell.setEncoding(HSSFCell.ENCODING_UTF_16); // 转换大写方式 totalString = szTzf(totalMoney); titleCell.setCellValue(totalString); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 11); titleCell.setCellStyle(contentStyle); // 设置单元格边框 titleRow = sheet.createRow((short) (i + 6)); titleCell = titleRow.createCell((short) 0); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 1); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 2); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 3); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 4); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 5); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 6); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 7); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 8); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 9); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 10); titleCell.setCellStyle(contentStyle); titleCell = titleRow.createCell((short) 11); titleCell.setCellStyle(contentStyle); sheet.addMergedRegion(new Region((i + 5), (short) 0, (i + 6), (short) 1)); sheet.addMergedRegion(new Region((i + 5), (short) 2, (i + 6), (short) 11)); // 表尾样式 HSSFCellStyle endStyle = workBook.createCellStyle(); endStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); endStyle.setBorderBottom(CellStyle.BORDER_THIN); endStyle.setBorderRight(CellStyle.BORDER_THIN); endStyle.setFont(contentFont); // sheet.getRow(0).getCell((short)0).setCellStyle(titleStyle); // sheet.getRow(1).getCell((short)0).setCellStyle(contentStyle); // sheet.getRow(1).getCell((short)1).setCellStyle(contentStyle); // sheet.getRow(2).getCell((short)1).setCellStyle(contentStyle); // sheet.getRow(2).getCell((short)1).setCellStyle(contentStyle); // 导出 HttpServletResponse resp = ServletActionContext.getResponse(); resp.setContentType("application/vnd.ms-excel"); resp.setCharacterEncoding("UFT-8"); String fileName = date + "学工部设备表.xls"; fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); resp.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); ServletOutputStream op = resp.getOutputStream(); op.flush(); workBook.write(op); op.close(); // return "toExcel"; /* * String fileName = date.toLocaleString().substring(0, 10)+ * "勤工助学酬劳发放表.xls"; FileOutputStream fileOut = new * FileOutputStream(fileName); workBook.write(fileOut); fileOut.close(); */ }
@SuppressWarnings("deprecation") public Reporteconcepto( Rgenerador objeto, Rgenerador objeto2, Boolean siinicial, String partida, String ruta, String ruta2, String path) throws IOException { this.FILE = path; // creacion del libro que contedra nuestro reporte libro = new HSSFWorkbook(); // cracion de la hoja que estara contenida en nuestro libro hoja = libro.createSheet("new sheet"); // Definicion de estilo que contendra nuestro encabezado // ***************************************************************************************************************************************************** // definicion estilos de celdas, establecimineto del tipo de fuente fuenteen = libro.createFont(); fuenteen.setFontHeightInPoints((short) 12); fuenteen.setFontName(fuenteen.FONT_ARIAL); fuenteen.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // Creacion del objeto que se encargara de aplicar el estilo a la celda esceldaen = libro.createCellStyle(); esceldaen.setWrapText(true); esceldaen.setAlignment(HSSFCellStyle.ALIGN_LEFT); esceldaen.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); esceldaen.setFont(fuenteen); // establecimiento de sombreado de nuestra celda esceldaen.setFillForegroundColor((short) 44); esceldaen.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // Definicion de estilo que contendra los tiulos // ***************************************************************************************************************************************************** // definicion estilos de celdas, establecimineto del tipo de fuente fuentet = libro.createFont(); fuentet.setFontHeightInPoints((short) 11); fuentet.setFontName(fuentet.FONT_ARIAL); fuentet.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // Creacion del objeto que se encargara de aplicar el estilo a la celda esceldat = libro.createCellStyle(); esceldat.setWrapText(true); esceldat.setAlignment(HSSFCellStyle.ALIGN_CENTER); esceldat.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); esceldat.setFont(fuentet); // establecimiento de bordes esceldat.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); esceldat.setBottomBorderColor((short) 8); esceldat.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); esceldat.setLeftBorderColor((short) 8); esceldat.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); esceldat.setRightBorderColor((short) 8); esceldat.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); esceldat.setRightBorderColor((short) 8); // establecimiento de sombreado de nuestra celda esceldat.setFillForegroundColor((short) 22); esceldat.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // ***************************************************************************************************************************************************** // Definicion del estilo de la celda de nuestros datos que contendra el // reporte // definicion estilos de celdas, establecimineto del tipo de fuente fuentein = libro.createFont(); fuentein.setFontHeightInPoints((short) 10); fuentein.setFontName(fuentein.FONT_ARIAL); fuentein.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // Creacion del objeto que se encargara de aplicar el estilo a la celda esceldain = libro.createCellStyle(); esceldain.setWrapText(true); esceldain.setAlignment(HSSFCellStyle.ALIGN_CENTER); esceldain.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); esceldain.setFont(fuentet); // establecimiento de bordes esceldain.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); esceldain.setBottomBorderColor((short) 8); esceldain.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); esceldain.setLeftBorderColor((short) 8); esceldain.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); esceldain.setRightBorderColor((short) 8); esceldain.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); esceldain.setRightBorderColor((short) 8); // definimos el numero de filas que contedra nuestro decumento. encabezado = hoja.createRow((short) 5); Cencabezado = encabezado.createCell((short) 2); Cencabezado.setCellValue("Datos Verificados: Partida(" + partida + ")"); hoja.addMergedRegion(new Region(5, (short) 2, 6, (short) 4)); Cencabezado.setCellStyle(esceldaen); // ******************************************************************************************************************** HSSFRow fila1 = hoja.createRow((short) 2); HSSFCell ccontrato = fila1.createCell((short) 8); ccontrato.setCellValue("contrato:"); ccontrato.setCellStyle(esceldain); HSSFCell rcontrato = fila1.createCell((short) 9); rcontrato.setCellValue(" "); rcontrato.setCellStyle(esceldain); HSSFCell cgenrencia = fila1.createCell((short) 10); cgenrencia.setCellValue("Gerencia:"); cgenrencia.setCellStyle(esceldain); HSSFCell rgerencia = fila1.createCell((short) 11); rgerencia.setCellValue(" "); rgerencia.setCellStyle(esceldain); HSSFCell choja = fila1.createCell((short) 12); choja.setCellValue("Hoja:"); choja.setCellStyle(esceldain); HSSFCell rhoja = fila1.createCell((short) 13); rhoja.setCellValue(" "); rhoja.setCellStyle(esceldain); // ******************************************************************************************************************************************************* HSSFRow fila2 = hoja.createRow((short) 3); HSSFCell cnc = fila2.createCell((short) 8); cnc.setCellValue("N.C. :"); cnc.setCellStyle(esceldain); HSSFCell rcnc = fila2.createCell((short) 9); rcnc.setCellValue(" "); rcnc.setCellStyle(esceldain); HSSFCell ctipo = fila2.createCell((short) 10); ctipo.setCellValue("Tipo de obra:"); ctipo.setCellStyle(esceldain); HSSFCell rtipo = fila2.createCell((short) 11); rtipo.setCellValue(" "); rtipo.setCellStyle(esceldain); HSSFCell cunidad = fila2.createCell((short) 12); cunidad.setCellValue("Unidad:"); cunidad.setCellStyle(esceldain); HSSFCell runidad = fila2.createCell((short) 13); runidad.setCellValue(" "); runidad.setCellStyle(esceldain); // ******************************************************************************************************************************************************* HSSFRow fila3 = hoja.createRow((short) 4); HSSFCell clocalidad = fila3.createCell((short) 8); clocalidad.setCellValue("localidad:"); clocalidad.setCellStyle(esceldain); HSSFCell rlocalidad = fila3.createCell((short) 9); rlocalidad.setCellValue(" "); rlocalidad.setCellStyle(esceldain); hoja.addMergedRegion(new Region(4, (short) 9, 4, (short) 11)); rlocalidad.setCellStyle(esceldain); HSSFCell runo = fila3.createCell((short) 10); runo.setCellValue(" "); runo.setCellStyle(esceldain); HSSFCell rdos = fila3.createCell((short) 11); rdos.setCellValue(" "); rdos.setCellStyle(esceldain); HSSFCell cfecha = fila3.createCell((short) 12); cfecha.setCellValue("Fecha:"); cfecha.setCellStyle(esceldain); HSSFCell rfecha = fila3.createCell((short) 13); rfecha.setCellValue(" "); rfecha.setCellStyle(esceldain); // *************************************************************************************************************************************************************** HSSFRow fila4 = hoja.createRow((short) 5); HSSFCell ccontratista = fila4.createCell((short) 8); ccontratista.setCellValue("Contratista:"); ccontratista.setCellStyle(esceldain); HSSFCell rcontratista = fila4.createCell((short) 9); rcontratista.setCellValue(" "); rcontratista.setCellStyle(esceldain); hoja.addMergedRegion(new Region(5, (short) 9, 5, (short) 13)); rcontratista.setCellStyle(esceldain); HSSFCell runoc = fila4.createCell((short) 10); runoc.setCellValue(" "); runoc.setCellStyle(esceldain); HSSFCell rdosc = fila4.createCell((short) 11); rdosc.setCellValue(" "); rdosc.setCellStyle(esceldain); HSSFCell rtres = fila4.createCell((short) 12); rtres.setCellValue(" "); rtres.setCellStyle(esceldain); HSSFCell rcuatro = fila4.createCell((short) 13); rcuatro.setCellValue(" "); rcuatro.setCellStyle(esceldain); // *************************************************************************************************************************************************************** HSSFRow fila5 = hoja.createRow((short) 6); HSSFCell cperiodo = fila5.createCell((short) 8); cperiodo.setCellValue("Consultor:"); cperiodo.setCellStyle(esceldain); HSSFCell rperiodo = fila5.createCell((short) 9); rperiodo.setCellValue(" "); rperiodo.setCellStyle(esceldain); hoja.addMergedRegion(new Region(6, (short) 9, 6, (short) 13)); rperiodo.setCellStyle(esceldain); HSSFCell runop = fila5.createCell((short) 10); runop.setCellValue(" "); runop.setCellStyle(esceldain); HSSFCell rdosp = fila5.createCell((short) 11); rdosp.setCellValue(" "); rdosp.setCellStyle(esceldain); HSSFCell rtresp = fila5.createCell((short) 12); rtresp.setCellValue(" "); rtresp.setCellStyle(esceldain); HSSFCell rcuatrop = fila5.createCell((short) 13); rcuatrop.setCellValue(" "); rcuatrop.setCellStyle(esceldain); // crear un una columna HSSFRow row1 = hoja.createRow((short) 7); // create de las celdas HSSFCell cc = row1.createCell((short) 2); HSSFCell cd = row1.createCell((short) 3); HSSFCell cu = row1.createCell((short) 4); HSSFCell cx = row1.createCell((short) 5); HSSFCell cy = row1.createCell((short) 6); HSSFCell cz = row1.createCell((short) 7); HSSFCell ca = row1.createCell((short) 8); HSSFCell cl = row1.createCell((short) 9); HSSFCell cal = row1.createCell((short) 10); HSSFCell cca = row1.createCell((short) 11); HSSFCell cpz = row1.createCell((short) 12); HSSFCell cim = row1.createCell((short) 13); // writing data to the cells cc.setCellValue("Clave"); cc.setCellStyle(esceldat); cd.setCellValue("Descripción"); cd.setCellStyle(esceldat); cu.setCellValue("Unidad"); cu.setCellStyle(esceldat); cx.setCellValue("X"); cx.setCellStyle(esceldat); cy.setCellValue("Y"); cy.setCellStyle(esceldat); cz.setCellValue("Z"); cz.setCellStyle(esceldat); ca.setCellValue("Alto"); ca.setCellStyle(esceldat); cl.setCellValue("Largo"); cl.setCellStyle(esceldat); cal.setCellValue("ancho"); cal.setCellStyle(esceldat); cca.setCellValue("Cantidad"); cca.setCellStyle(esceldat); cpz.setCellValue("Piezas"); cpz.setCellStyle(esceldat); cim.setCellValue("Importe"); cim.setCellStyle(esceldat); // crear un una columna HSSFRow row = hoja.createRow((short) 8); // create de las celdas HSSFCell cc1 = row.createCell((short) 2); HSSFCell cd1 = row.createCell((short) 3); HSSFCell cu1 = row.createCell((short) 4); HSSFCell cx1 = row.createCell((short) 5); HSSFCell cy1 = row.createCell((short) 6); HSSFCell cz1 = row.createCell((short) 7); HSSFCell ca1 = row.createCell((short) 8); HSSFCell cl1 = row.createCell((short) 9); HSSFCell cal1 = row.createCell((short) 10); HSSFCell cca1 = row.createCell((short) 11); HSSFCell cpz1 = row.createCell((short) 12); HSSFCell cim1 = row.createCell((short) 13); cc1.setCellValue(objeto.getClave()); cc1.setCellStyle(esceldain); cd1.setCellValue(objeto.getDescripcion()); cd1.setCellStyle(esceldain); cu1.setCellValue(objeto.getUnidad()); cu1.setCellStyle(esceldain); cx1.setCellValue(objeto.getX()); cx1.setCellStyle(esceldain); cy1.setCellValue(objeto.getY()); cy1.setCellStyle(esceldain); cz1.setCellValue(objeto.getZ()); cz1.setCellStyle(esceldain); ca1.setCellValue(objeto.getAlto()); ca1.setCellStyle(esceldain); cl1.setCellValue(objeto.getLargo()); cl1.setCellStyle(esceldain); cal1.setCellValue(objeto.getAncho()); cal1.setCellStyle(esceldain); cca1.setCellValue(objeto.getCantidad()); cca1.setCellStyle(esceldain); cpz1.setCellValue(objeto.getPiezas()); cpz1.setCellStyle(esceldain); cim1.setCellValue(objeto.getImporte()); cim1.setCellStyle(esceldain); HSSFSheet sheet = libro.getSheetAt(0); HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); // contendor que contiene las imagenes HSSFClientAnchor anchor; if (ruta != null) { File fis = new File(ruta); anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 3, 11, (short) 5, 24); anchor.setAnchorType(2); HSSFPicture imagen = patriarch.createPicture(anchor, Cargarimagen(fis, libro)); } if (ruta2 != null) { File fis2 = new File(ruta2); anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 9, 11, (short) 12, 24); anchor.setAnchorType(2); HSSFPicture imagen2 = patriarch.createPicture(anchor, Cargarimagen(fis2, libro)); } sheet.autoSizeColumn((short) 2); sheet.autoSizeColumn((short) 3); sheet.autoSizeColumn((short) 4); sheet.autoSizeColumn((short) 5); sheet.autoSizeColumn((short) 6); sheet.autoSizeColumn((short) 7); sheet.autoSizeColumn((short) 8); sheet.autoSizeColumn((short) 9); sheet.autoSizeColumn((short) 10); sheet.autoSizeColumn((short) 11); sheet.autoSizeColumn((short) 12); sheet.autoSizeColumn((short) 13); if (siinicial == true) { // ************************************************************************************ HSSFRow encabezado2 = hoja.createRow((short) 26); HSSFCell Cencabezado2 = encabezado2.createCell((short) 2); Cencabezado2.setCellValue("Datos: Partida(" + partida + ")"); hoja.addMergedRegion(new Region(26, (short) 2, 27, (short) 4)); Cencabezado2.setCellStyle(esceldaen); // crear un una columna HSSFRow row27 = hoja.createRow((short) 28); // create de las celdas HSSFCell cc2 = row27.createCell((short) 2); HSSFCell cd2 = row27.createCell((short) 3); HSSFCell cu2 = row27.createCell((short) 4); HSSFCell cx2 = row27.createCell((short) 5); HSSFCell cy2 = row27.createCell((short) 6); HSSFCell cz2 = row27.createCell((short) 7); HSSFCell ca2 = row27.createCell((short) 8); HSSFCell cl2 = row27.createCell((short) 9); HSSFCell cal2 = row27.createCell((short) 10); HSSFCell cca2 = row27.createCell((short) 11); HSSFCell cpz2 = row27.createCell((short) 12); HSSFCell cim2 = row27.createCell((short) 13); // writing data to the cells cc2.setCellValue("Clave"); cc2.setCellStyle(esceldat); cd2.setCellValue("Descripción"); cd2.setCellStyle(esceldat); cu2.setCellValue("Unidad"); cu2.setCellStyle(esceldat); cx2.setCellValue("X"); cx2.setCellStyle(esceldat); cy2.setCellValue("Y"); cy2.setCellStyle(esceldat); cz2.setCellValue("Z"); cz2.setCellStyle(esceldat); ca2.setCellValue("Alto"); ca2.setCellStyle(esceldat); cl2.setCellValue("Largo"); cl2.setCellStyle(esceldat); cal2.setCellValue("ancho"); cal2.setCellStyle(esceldat); cca2.setCellValue("Cantidad"); cca2.setCellStyle(esceldat); cpz2.setCellValue("Piezas"); cpz2.setCellStyle(esceldat); cim2.setCellValue("Importe"); cim2.setCellStyle(esceldat); // crear un una columna HSSFRow row28 = hoja.createRow((short) 29); // create de las celdas HSSFCell cc12 = row28.createCell((short) 2); HSSFCell cd12 = row28.createCell((short) 3); HSSFCell cu12 = row28.createCell((short) 4); HSSFCell cx12 = row28.createCell((short) 5); HSSFCell cy12 = row28.createCell((short) 6); HSSFCell cz12 = row28.createCell((short) 7); HSSFCell ca12 = row28.createCell((short) 8); HSSFCell cl12 = row28.createCell((short) 9); HSSFCell cal12 = row28.createCell((short) 10); HSSFCell cca12 = row28.createCell((short) 11); HSSFCell cpz12 = row28.createCell((short) 12); HSSFCell cim12 = row28.createCell((short) 13); cc12.setCellValue(objeto2.getClave()); cc12.setCellStyle(esceldain); cd12.setCellValue(objeto2.getDescripcion()); cd12.setCellStyle(esceldain); cu12.setCellValue(objeto2.getUnidad()); cu12.setCellStyle(esceldain); cx12.setCellValue(objeto2.getX()); cx12.setCellStyle(esceldain); cy12.setCellValue(objeto2.getY()); cy12.setCellStyle(esceldain); cz12.setCellValue(objeto2.getZ()); cz12.setCellStyle(esceldain); ca12.setCellValue(objeto2.getAlto()); ca12.setCellStyle(esceldain); cl12.setCellValue(objeto2.getLargo()); cl12.setCellStyle(esceldain); cal12.setCellValue(objeto2.getAncho()); cal12.setCellStyle(esceldain); cca12.setCellValue(objeto2.getCantidad()); cca12.setCellStyle(esceldain); cpz12.setCellValue(objeto2.getPiezas()); cpz12.setCellStyle(esceldain); cim12.setCellValue(objeto2.getImporte()); cim12.setCellStyle(esceldain); float uno = 0, dos = 0, resultado = 0; uno = Float.parseFloat(objeto.getImporte()); dos = Float.parseFloat(objeto2.getImporte()); if (uno > dos) { HSSFRow row31 = hoja.createRow((short) 33); // create de las celdas HSSFCell cc131 = row31.createCell((short) 3); resultado = uno - dos; cc131.setCellValue("Execedente: " + String.valueOf(resultado)); cc131.setCellStyle(esceldain); } else { if (dos > uno) { HSSFRow row31 = hoja.createRow((short) 33); // create de las celdas HSSFCell cc131 = row31.createCell((short) 3); resultado = dos - uno; cc131.setCellValue("Restante: " + String.valueOf(resultado)); cc131.setCellStyle(esceldain); } } // **************************************************************************************** } else { HSSFRow encabezado2 = hoja.createRow((short) 26); HSSFCell Cencabezado2 = encabezado2.createCell((short) 2); Cencabezado2.setCellValue( "El aspecto:" + objeto.getDescripcion() + " no esta comtemplado en la estimacion inicial"); hoja.addMergedRegion(new Region(26, (short) 2, 27, (short) 4)); Cencabezado2.setCellStyle(esceldaen); HSSFRow row28 = hoja.createRow((short) 29); // create de las celdas HSSFCell cc12 = row28.createCell((short) 3); cc12.setCellValue("Execedente: " + objeto.getImporte()); cc12.setCellStyle(esceldain); } try { FileOutputStream elFichero = new FileOutputStream(FILE); libro.write(elFichero); elFichero.close(); } catch (Exception e) { e.printStackTrace(); } }