title: How to auto adjust the column in excel in apache POI
body: <p>I am creating an excel file  with apache poi the excel is generated  but i  can not adjust the column with  according to the cell values  i am posting the code what i have done so  far</p>
  
  <p>This is how i have created the  headers in excel </p>
  
  <pre><code>HSSFWorkbook wb = new HSSFWorkbook();
          HSSFSheet sheet = wb.createSheet();
          sheet.protectSheet("password");
          sheet.autoSizeColumn(15);
          HSSFFont hSSFFont = wb.createFont();
          hSSFFont.setFontName(HSSFFont.FONT_ARIAL);
          hSSFFont.setFontHeightInPoints((short) 8);
  
          CellStyle style = wb.createCellStyle();
          /* cell style for locking */
          CellStyle lockedCellStyle = wb.createCellStyle();
          lockedCellStyle.setLocked(true);
  
          HSSFRow row = null;
  
          HSSFCell cell = null;
  
          row = sheet.createRow(0);
          int headercolumnNo = 0;
  
  
  
          //1st Column Header for Indicator
          cell = row.createCell(headercolumnNo);
          cell.setCellValue(new HSSFRichTextString(listOfActiveCarrierUserHeader.get(0)));
          style.setWrapText(true);
          style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
          style.setFont(hSSFFont);
          style.setFillPattern(CellStyle.SOLID_FOREGROUND);
          cell.setCellStyle(style);
          headercolumnNo = 1;
  
          cell = row.createCell(headercolumnNo);  //2nd Column Header for Firstname
          cell.setCellValue(new HSSFRichTextString(listOfActiveCarrierUserHeader.get(1)));
          style.setWrapText(true);
          style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
          style.setFont(hSSFFont);
          cell.setCellStyle(style);
          headercolumnNo = headercolumnNo + 1;
  
          cell = row.createCell(headercolumnNo);  //2nd Column Header for Firstname
          cell.setCellValue(new HSSFRichTextString(listOfActiveCarrierUserHeader.get(2)));
          style.setWrapText(true);
          style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
          style.setFont(hSSFFont);
          cell.setCellStyle(style);
          headercolumnNo = headercolumnNo + 1;
  
  and this is how i have  populated the values in that excel file 
  
  for(CarrierActiveUser carrierActiveUser : listOfCarrierUser){
  
              int columnNo = 0;
              row = sheet.createRow(j + 1);
  
              cell = row.createCell(columnNo);
              if(null != carrierActiveUser.getFistName()){
  
                  cell.setCellValue(new HSSFRichTextString(carrierActiveUser.getFistName()));
                   lockedCellStyle.setFont(hSSFFont);
                   cell.setCellStyle(lockedCellStyle);
  
              }else{
                  cell.setCellValue(new HSSFRichTextString(" "));
                  cell.setCellStyle(lockedCellStyle);
              }
  
              columnNo = columnNo + 1;
              cell = row.createCell(columnNo);
              if(null != carrierActiveUser.getLastName()){
  
                  cell.setCellValue(new HSSFRichTextString(carrierActiveUser.getLastName()));
                     lockedCellStyle.setFont(hSSFFont);
                  cell.setCellStyle(lockedCellStyle);
  
              }else{
                  cell.setCellValue(new HSSFRichTextString(" "));
                  cell.setCellStyle(lockedCellStyle);
              }
  
              columnNo = columnNo + 1;
              cell = row.createCell(columnNo);
              if(null != carrierActiveUser.getLastName()){
  
                  cell.setCellValue(new HSSFRichTextString(carrierActiveUser.getEmailId()));
                  lockedCellStyle.setFont(hSSFFont);
                  cell.setCellStyle(lockedCellStyle);
  
              }else{
                  cell.setCellValue(new HSSFRichTextString(" "));
                  cell.setCellStyle(lockedCellStyle);
              }
  </code></pre>
  
  <p>Please someone help me to  adjust the columns , i am new to apache poi </p>
  
  <p><img src="https://i.stack.imgur.com/APHuG.png" alt="Current output"></p>