List of usage examples for org.apache.poi.ss.usermodel Cell setCellStyle
void setCellStyle(CellStyle style);
Set the style for the cell.
From source file:com.springapp.mvc.BusinessPlan.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb;/*from ww w . j a v a 2 s . c o m*/ if (args.length > 0 && args[0].equals("-xls")) wb = new HSSFWorkbook(); else wb = new XSSFWorkbook(); Map<String, CellStyle> styles = createStyles(wb); Sheet sheet = wb.createSheet("Business Plan"); //turn off gridlines sheet.setDisplayGridlines(false); sheet.setPrintGridlines(false); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); //the following three statements are required only for HSSF sheet.setAutobreaks(true); printSetup.setFitHeight((short) 1); printSetup.setFitWidth((short) 1); //the header row: centered text in 48pt font Row headerRow = sheet.createRow(0); headerRow.setHeightInPoints(12.75f); for (int i = 0; i < titles.length; i++) { Cell cell = headerRow.createCell(i); cell.setCellValue(titles[i]); cell.setCellStyle(styles.get("header")); } //columns for 11 weeks starting from 9-Jul Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); //calendar.setTime(fmt.parse("9-11")); calendar.set(Calendar.YEAR, year); for (int i = 0; i < 11; i++) { Cell cell = headerRow.createCell(titles.length + i); cell.setCellValue(calendar); cell.setCellStyle(styles.get("header_date")); calendar.roll(Calendar.WEEK_OF_YEAR, true); } //freeze the first row sheet.createFreezePane(0, 1); Row row; Cell cell; int rownum = 1; for (int i = 0; i < data.length; i++, rownum++) { row = sheet.createRow(rownum); if (data[i] == null) continue; for (int j = 0; j < data[i].length; j++) { cell = row.createCell(j); String styleName; boolean isHeader = i == 0 || data[i - 1] == null; switch (j) { case 0: if (isHeader) { styleName = "cell_b"; cell.setCellValue(Double.parseDouble(data[i][j])); } else { styleName = "cell_normal"; cell.setCellValue(data[i][j]); } break; case 1: if (isHeader) { styleName = i == 0 ? "cell_h" : "cell_bb"; } else { styleName = "cell_indented"; } cell.setCellValue(data[i][j]); break; case 2: styleName = isHeader ? "cell_b" : "cell_normal"; cell.setCellValue(data[i][j]); break; case 3: styleName = isHeader ? "cell_b_centered" : "cell_normal_centered"; cell.setCellValue(Integer.parseInt(data[i][j])); break; case 4: { //calendar.setTime(fmt.parse(data[i][j])); calendar.set(Calendar.YEAR, year); cell.setCellValue(calendar); styleName = isHeader ? "cell_b_date" : "cell_normal_date"; break; } case 5: { int r = rownum + 1; String fmla = "IF(AND(D" + r + ",E" + r + "),E" + r + "+D" + r + ",\"\")"; cell.setCellFormula(fmla); styleName = isHeader ? "cell_bg" : "cell_g"; break; } default: styleName = data[i][j] != null ? "cell_blue" : "cell_normal"; } cell.setCellStyle(styles.get(styleName)); } } //group rows for each phase, row numbers are 0-based sheet.groupRow(4, 6); sheet.groupRow(9, 13); sheet.groupRow(16, 18); //set column widths, the width is measured in units of 1/256th of a character width sheet.setColumnWidth(0, 256 * 6); sheet.setColumnWidth(1, 256 * 33); sheet.setColumnWidth(2, 256 * 20); sheet.setZoom(3, 4); // Write the output to a file String file = "businessplan.xls"; if (wb instanceof XSSFWorkbook) file += "x"; FileOutputStream out = new FileOutputStream(file); wb.write(out); out.close(); }
From source file:com.squid.core.poi.ExcelWriter.java
License:Open Source License
private void writeNext(final Object[] nextLine, final boolean isHeader, String[] columnsFormat, int[] cellsType) { Row row = getRow();//from w ww.j a v a 2 s.c om for (int iCell = 0; iCell < nextLine.length; iCell++) { Cell cell = row.createCell(iCell); // Create cell if (isHeader) { // Apply header and footer style cell.getRow().setHeight((short) 500); } Object value = nextLine[iCell]; String format = "General"; if (columnsFormat != null && columnsFormat.length > iCell && columnsFormat[iCell] != null) { cell.setCellStyle(getStyle(columnsFormat[iCell])); } else { cell.setCellStyle(getStyle(format)); } // Guess cell data type if (cellsType != null && cellsType.length > iCell) { cell.setCellType(cellsType[iCell]); } else { cell.setCellType(Cell.CELL_TYPE_STRING); } if (value instanceof String) { cell.setCellValue((String) value); } else if (value instanceof Date) { cell.setCellValue((Date) value); } else if (value instanceof Boolean) { cell.setCellValue((Boolean) value); } else if (value instanceof Number) { String durationFormat = ""; if (columnsFormat != null && columnsFormat.length > iCell && columnsFormat[iCell] != null) { durationFormat = columnsFormat[iCell]; } if (DurationFormatUtils.isDurationFormatPattern(durationFormat)) { cell.setCellValue(DurationFormatUtils.format(durationFormat, ((Number) value).doubleValue())); } else { cell.setCellValue(((Number) value).doubleValue()); } } } }
From source file:com.tecnosur.util.Excel.java
public void ExportarMatriculados(CControlmatricula datos, String aula) { try { // Defino el Libro de Excel HSSFWorkbook wb = new HSSFWorkbook(); // Creo la Hoja en Excel Sheet sheet = wb.createSheet("matriculados"); // quito las lineas del libro para darle un mejor acabado sheet.setDisplayGridlines(false); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); // creo una nueva fila Row trow = sheet.createRow((short) 1); createTituloCell(wb, trow, 0, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "ALUMNOS MATRICULADOS"); Row trow2 = sheet.createRow((short) 3); createTituloCell(wb, trow2, 0, CellStyle.ALIGN_LEFT, CellStyle.VERTICAL_CENTER, "AULA: " + aula); // Creo la cabecera de mi listado en Excel Row row = sheet.createRow((short) 5); // Creo las celdas de mi fila, se puede poner un diseo a la celda_codigo createCell(wb, row, 0, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "CDIGO", true, true); createCell(wb, row, 1, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "ALUMNO", true, true); createCell(wb, row, 2, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "TIPO PAGO", true, true); createCell(wb, row, 3, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "CRONO. PAGO", true, true); createCell(wb, row, 4, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "N CUOT.", true, true); createCell(wb, row, 5, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "MON. MATR.", true, true); createCell(wb, row, 6, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "MON. CUOT.", true, true); // Definimos el tamao de las celdas, podemos definir un tamaa especifico o hacer que //la celda_codigo se acomode segn su tamao Sheet ssheet = wb.getSheetAt(0); ssheet.setColumnWidth(0, 60 * 40); ssheet.setColumnWidth(1, 255 * 40); ssheet.setColumnWidth(2, 90 * 40); ssheet.autoSizeColumn(3);/* w w w. ja v a 2 s . co m*/ ssheet.autoSizeColumn(4); ssheet.autoSizeColumn(5); ssheet.autoSizeColumn(6); HSSFFont cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 8); cellFont.setFontName(HSSFFont.FONT_ARIAL); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(cellFont); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); for (int i = 0; i < datos.size(); i++) { row = sheet.createRow((short) i + 6); Cell celda_codigo = row.createCell(0); celda_codigo.setCellStyle(cellStyle); celda_codigo.setCellValue(datos.get(i).getIdalumno()); Cell celda_alumno = row.createCell(1); celda_alumno.setCellStyle(cellStyle); celda_alumno.setCellValue(datos.get(i).getNom_completo()); Cell celda_tipopago = row.createCell(2); celda_tipopago.setCellStyle(cellStyle); celda_tipopago.setCellValue(datos.get(i).getTipopagante()); Cell celda_crono = row.createCell(3); celda_crono.setCellStyle(cellStyle); celda_crono.setCellValue(datos.get(i).getDesc_cronopagtable()); Cell celda_ncuota = row.createCell(4); celda_ncuota.setCellStyle(cellStyle); celda_ncuota.setCellValue(datos.get(i).getNum_cuota()); Cell celda_matricula = row.createCell(5); celda_matricula.setCellStyle(cellStyle); celda_matricula.setCellValue(datos.get(i).getMonmatricula()); Cell celda_moncuota = row.createCell(6); celda_moncuota.setCellStyle(cellStyle); celda_moncuota.setCellValue(datos.get(i).getMoncuota()); } String strRuta = "TYSAC_Matriculados.xls"; FileOutputStream fileOut = new FileOutputStream(strRuta); wb.write(fileOut); fileOut.close(); Runtime.getRuntime().exec("cmd /c start " + strRuta); } catch (IOException e) { System.out.println("Error de escritura"); e.printStackTrace(); } }
From source file:com.tecnosur.util.Excel.java
private static void createTituloCell(HSSFWorkbook wb, Row row, int column, short halign, short valign, String strContenido) {//from w ww . j ava 2s . co m CreationHelper ch = wb.getCreationHelper(); Cell cell = row.createCell(column); cell.setCellValue(ch.createRichTextString(strContenido)); HSSFFont cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 11); cellFont.setFontName(HSSFFont.FONT_ARIAL); cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); cellStyle.setFont(cellFont); cell.setCellStyle(cellStyle); }
From source file:com.tecnosur.util.Excel.java
private static void createCell(HSSFWorkbook wb, Row row, int column, short halign, short valign, String strContenido, boolean booBorde, boolean booCabecera) { CreationHelper ch = wb.getCreationHelper(); Cell cell = row.createCell(column); HSSFFont cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 8); cellFont.setFontName(HSSFFont.FONT_ARIAL); cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cell.setCellValue(ch.createRichTextString(strContenido)); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign);/*w w w .jav a 2s . c om*/ cellStyle.setVerticalAlignment(valign); cellStyle.setFont(cellFont); if (booBorde) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setTopBorderColor((short) 8); } if (booCabecera) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setTopBorderColor((short) 8); cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); } cell.setCellStyle(cellStyle); }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.AbstractSeccionXLS.java
License:Apache License
public void paintBorder(XSSFWorkbook wb, Sheet sheet, short borderType, BordeSeccion borde) { for (int i = borde.getUpperRow(); i <= borde.getLowerRow(); i++) { Row row = sheet.getRow(i);//from ww w . jav a 2 s .c om for (int j = borde.getLeftColumn(); j <= borde.getRightColumn(); j++) { if (i == borde.getUpperRow() || i == borde.getLowerRow() || j == borde.getLeftColumn() || j == borde.getRightColumn()) { Cell cell = row.getCell(j); XSSFCellStyle actual = (XSSFCellStyle) cell.getCellStyle(); XSSFCellStyle nuevo = wb.createCellStyle(); nuevo.cloneStyleFrom(actual); if (i == borde.getUpperRow()) { nuevo.setBorderTop(borderType); nuevo.setTopBorderColor(IndexedColors.BLACK.getIndex()); } if (i == borde.getLowerRow()) { nuevo.setBorderBottom(borderType); nuevo.setBottomBorderColor(IndexedColors.BLACK.getIndex()); } if (j == borde.getLeftColumn()) { nuevo.setBorderLeft(borderType); nuevo.setLeftBorderColor(IndexedColors.BLACK.getIndex()); } if (j == borde.getRightColumn()) { nuevo.setBorderRight(borderType); nuevo.setRightBorderColor(IndexedColors.BLACK.getIndex()); } cell.setCellStyle(nuevo); } } } }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.BitacoraReporteCliente.java
License:Apache License
@Override public BordeSeccion generar(BordeSeccion borde, ContextoSeccion contexto, ReporteCliente datos) { Sheet sheet = contexto.getSheet();//from w w w . j av a 2 s. c o m XSSFWorkbook wb = contexto.getWb(); int initialRow = borde.getUpperRow(); int initialColumn = borde.getLeftColumn(); BordeSeccion r = new BordeSeccion(); r.setLeftColumn(initialColumn); r.setUpperRow(initialRow); Row row = getRow(sheet, initialRow); Cell cell = row.createCell(initialColumn); cell.setCellValue("Bitacora"); XSSFCellStyle cellStyle = wb.createCellStyle(); addHeaderStyle(cellStyle, wb); addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); for (int i = 1; i < 4; i++) { cell = row.createCell(initialColumn + i); cellStyle = wb.createCellStyle(); addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } //merge de celdas sheet.addMergedRegion(new CellRangeAddress(initialRow, //first row (0-based) initialRow, //last row (0-based) initialColumn, //first column (0-based) initialColumn + 3 //last column (0-based) )); CreationHelper createHelper = wb.getCreationHelper(); for (EventoRC x : datos.getBitacora()) { initialRow = initialRow + 1; row = getRow(sheet, initialRow); for (int i = 0; i < atributos.length; i++) { cell = row.createCell(initialColumn + i); cellStyle = wb.createCellStyle(); try { if (atributos[i].equals("fecha")) { cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("yy/m/d h:mm:ss")); cell.setCellValue((Date) PropertyUtils.getProperty(x, atributos[i])); } else { cell.setCellValue(PropertyUtils.getProperty(x, atributos[i]).toString()); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { cell.setCellValue(""); } addBorders(wb, cellStyle, CellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); } } r.setLowerRow(initialRow); r.setRightColumn(initialColumn + 3); paintBorder(wb, sheet, CellStyle.BORDER_MEDIUM, r); return r; }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.CostoHojalateriaReporteCliente.java
License:Apache License
@Override public BordeSeccion generar(BordeSeccion borde, ContextoSeccion contexto, ReporteCliente datos) { Sheet sheet = contexto.getSheet();// w w w . j av a 2 s . com XSSFWorkbook wb = contexto.getWb(); int initialRow = borde.getUpperRow(); int initialColumn = borde.getLeftColumn(); BordeSeccion r = new BordeSeccion(); r.setLeftColumn(initialColumn); r.setUpperRow(initialRow); Cell cell; Row row = getRow(sheet, initialRow); cell = row.createCell(initialColumn); cell.setCellValue("Hojalteria y pintura"); XSSFCellStyle cellStyle = wb.createCellStyle(); addHeaderStyle(cellStyle, wb); addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); for (int i = 1; i < 3; i++) { cell = row.createCell(initialColumn + i); cellStyle = wb.createCellStyle(); addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } //merge de celdas sheet.addMergedRegion(new CellRangeAddress(initialRow, //first row (0-based) initialRow, //last row (0-based) initialColumn, //first column (0-based) initialColumn + 2 //last column (0-based) )); //detalle cellStyle = wb.createCellStyle(); XSSFDataFormat df = wb.createDataFormat(); cellStyle.setDataFormat(df.getFormat("$#,##0.00")); Cell inicio = null; Cell fin = null; for (RegistroCostoRC x : datos.getRegistroHojalateriaPintura()) { initialRow = initialRow + 1; row = getRow(sheet, initialRow); //tipo cell = row.createCell(initialColumn); cell.setCellValue(x.getTipo()); //descripcion cell = row.createCell(initialColumn + 1); cell.setCellValue(x.getDescripcion()); //costo cell = row.createCell(initialColumn + 2); cell.setCellValue(x.getCosto()); cell.setCellStyle(cellStyle); if (inicio == null) { inicio = cell; } } if (inicio != null) { fin = cell; } initialRow = initialRow + 1; row = getRow(sheet, initialRow); cell = row.createCell(initialColumn + 1); cell.setCellValue("Total"); cellStyle = wb.createCellStyle(); XSSFFont font = wb.createFont(); font.setBold(true); cellStyle.setFont(font); cell.setCellStyle(cellStyle); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); cellStyle.setDataFormat(df.getFormat("$#,##0.00")); cell = row.createCell(initialColumn + 2); cell.setCellStyle(cellStyle); if (inicio != null) { String formula = "SUM(" + getSimpleReference(inicio) + ":" + getSimpleReference(fin) + ")"; cell.setCellFormula(formula); contexto.put("totalHojalateria", cell); } else { cell.setCellValue(0.0); } r.setLowerRow(initialRow); r.setRightColumn(initialColumn + 2); BordeSeccion sinTotal = new BordeSeccion(r); sinTotal.setLowerRow(r.getLowerRow() - 1); paintBorder(wb, sheet, CellStyle.BORDER_MEDIUM, sinTotal); return r; }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.CostoMecanicaReporteCliente.java
License:Apache License
@Override public BordeSeccion generar(BordeSeccion borde, ContextoSeccion contexto, ReporteCliente datos) { Sheet sheet = contexto.getSheet();//w w w . j ava2 s .com XSSFWorkbook wb = contexto.getWb(); int initialRow = borde.getUpperRow(); int initialColumn = borde.getLeftColumn(); BordeSeccion r = new BordeSeccion(); r.setLeftColumn(initialColumn); r.setUpperRow(initialRow); Cell cell; Row row = getRow(sheet, initialRow); cell = row.createCell(initialColumn); cell.setCellValue("Mecanica"); XSSFCellStyle cellStyle = wb.createCellStyle(); addHeaderStyle(cellStyle, wb); addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); for (int i = 1; i < 3; i++) { cell = row.createCell(initialColumn + i); cellStyle = wb.createCellStyle(); addBorders(wb, cellStyle, CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } //merge de celdas sheet.addMergedRegion(new CellRangeAddress(initialRow, //first row (0-based) initialRow, //last row (0-based) initialColumn, //first column (0-based) initialColumn + 2 //last column (0-based) )); //detalle cellStyle = wb.createCellStyle(); XSSFDataFormat df = wb.createDataFormat(); cellStyle.setDataFormat(df.getFormat("$#,##0.00")); Cell inicio = null; Cell fin = null; for (RegistroCostoRC x : datos.getRegistroMecanica()) { initialRow = initialRow + 1; row = getRow(sheet, initialRow); //tipo cell = row.createCell(initialColumn); cell.setCellValue(x.getTipo()); //descripcion cell = row.createCell(initialColumn + 1); cell.setCellValue(x.getDescripcion()); //costo cell = row.createCell(initialColumn + 2); cell.setCellValue(x.getCosto()); cell.setCellStyle(cellStyle); if (inicio == null) { inicio = cell; } } if (inicio != null) { fin = cell; } initialRow = initialRow + 1; row = getRow(sheet, initialRow); cell = row.createCell(initialColumn + 1); cell.setCellValue("Total"); cellStyle = wb.createCellStyle(); XSSFFont font = wb.createFont(); font.setBold(true); cellStyle.setFont(font); cell.setCellStyle(cellStyle); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); cellStyle.setDataFormat(df.getFormat("$#,##0.00")); cell = row.createCell(initialColumn + 2); cell.setCellStyle(cellStyle); if (inicio != null) { String formula = "SUM(" + getSimpleReference(inicio) + ":" + getSimpleReference(fin) + ")"; cell.setCellFormula(formula); contexto.put("totalMecanica", cell); } else { cell.setCellValue(0.0); } r.setLowerRow(initialRow); r.setRightColumn(initialColumn + 2); BordeSeccion sinTotal = new BordeSeccion(r); sinTotal.setLowerRow(r.getLowerRow() - 1); paintBorder(wb, sheet, CellStyle.BORDER_MEDIUM, sinTotal); return r; }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.DatosAutoReporteCliente.java
License:Apache License
@Override public BordeSeccion generar(BordeSeccion borde, ContextoSeccion contexto, ReporteCliente datos) { Sheet sheet = contexto.getSheet();/* ww w.j av a 2s .co m*/ XSSFWorkbook wb = contexto.getWb(); int initialRow = borde.getUpperRow(); int initialColumn = borde.getLeftColumn(); BordeSeccion r = new BordeSeccion(); r.setLeftColumn(initialColumn); r.setUpperRow(initialRow); //escribir el primer renglon Row row = getRow(sheet, initialRow); Cell cell = row.createCell(initialColumn); cell.setCellValue("Auto"); //estilo .-. XSSFCellStyle cellStyle = wb.createCellStyle(); addHeaderStyle(cellStyle, wb); addBorders(wb, cellStyle, CellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); for (int i = 1; i < encabezados.length; i++) { cell = row.createCell(initialColumn + i); cellStyle = wb.createCellStyle(); addBorders(wb, cellStyle, CellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); } //merge de celdas sheet.addMergedRegion(new CellRangeAddress(initialRow, //first row (0-based) initialRow, //last row (0-based) initialColumn, //first column (0-based) initialColumn + 7 //last column (0-based) )); //segundo renglon encabezado initialRow = initialRow + 1; row = getRow(sheet, initialRow); for (int i = 0; i < encabezados.length; i++) { cell = row.createCell(initialColumn + i); cell.setCellValue(encabezados[i]); cellStyle = wb.createCellStyle(); addHeaderStyle(cellStyle, wb); addBorders(wb, cellStyle, CellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); } //tercer renglon encabezado initialRow = initialRow + 1; row = getRow(sheet, initialRow); for (int i = 0; i < atributos.length; i++) { cell = row.createCell(initialColumn + i); try { cell.setCellValue(PropertyUtils.getProperty(datos, "auto." + atributos[i]).toString()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { cell.setCellValue(""); } cellStyle = wb.createCellStyle(); addBorders(wb, cellStyle, CellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); } r.setLowerRow(initialRow); r.setRightColumn(initialColumn + 7); paintBorder(wb, sheet, CellStyle.BORDER_MEDIUM, r); return r; }