Generation of column in Excel with java without losing format (poi)

0

I've been looking for a way to generate an excel from java with the correct format for a couple of days. I have to make a table with their column names and above the name of the columns should put a title. The problem is that if a title is added in the first column, the format I have of the columns in the tables is lost. I want to use a format only for that column of the title and that does not affect the table that I have just below. This I put below if I do not put the table just below it comes out correctly taking several cells but putting it with the table introduces all the data that I have put of the title in a cell what causes that the table does not remain correctly. On the other hand I also want to appear with the format that appears in the first column of the table but only get me to do the format for the entire column until the end and I do not know how to adjust it to the cells used by the table.

        // Esto seria mi titulo 
        HSSFRow row = sheet.createRow((short)0);
          row.setHeight((short) 600);
          HSSFCell cell = (HSSFCell) row.createCell((short) 1);
          cell.setCellValue("Este es el titulo de la tabla"); 

          //esto seria el nombre de cada columna 
            HSSFRow headerRow = sheet.createRow(rowIndex++);
            List<String> headerValues = ReportExcel
                    .getTableHeaderPedidos();
            HSSFCell headerCell = null;

for (int i = 0; i < headerValues.size(); i++) {
                headerCell = headerRow.createCell(i);
                headerCell.setCellStyle(style);
                headerCell.setCellValue(headerValues.get(i));
            }

Greetings and thanks for your time.

    
asked by kiristof 06.09.2017 в 09:31
source

1 answer

1

You could use the following

int start-col = 0; //para ser row 1
int end-col = 0; // para ser row 1
int start-cell = 0; // para ser A1 
int end-cell = 7;// para ser H1
sheet.addMergedRegion(new CellRangeAddress(start-col,end-col,start-cell,end-cell));

that's to merge the cells.

    
answered by 06.09.2017 / 20:52
source