Share

Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Apache poi' - 2 code snippet(s) found

 Sample 1. Load XLS file and print first column using poi XSSFWorkbook

public XSSFWorkbook loadXLSAndPrintFirstColumn(File xlsFile) {
   InputStream inputStream = null;
   try {
      inputStream = new FileInputStream(xlsFile);
   XSSFWorkbook xssFWorkbook = new XSSFWorkbook(inputStream);
      Sheet sheet = workbook.getSheetAt(workbook.getActiveSheetIndex());
      for (int index = 0; index < sheet.getPhysicalNumberOfRows(); index++) {
      try {
         Row row = sheet.getRow(index);
            System.out.println(row.getCell(0,Row.CREATE_NULL_AS_BLANK).getStringCellValue()));   
      } catch (Exception e) {
      System.out.println("Exception");
   }
}

}

   Like      Feedback     readinf xls  reading excel  apache poi  XSSFWorkbook  InputStream


 Sample 2. Get First Row values from a XLS Sheet using Apache POI ?

private String[] getFirstRow(Sheet sheet) {
Row firstRow = sheet.getRow(0);
int totalColumns = headerRow.getPhysicalNumberOfCells();
if (totalColumns > 0){
String[] columnHeaders = new String[totalColumns];
for (int count=0; count<columnHeaders.length; count++){
columnHeaders[count] = getValue(headerRow.getCell(count));
}
return columnHeaders;
}

return null;
}

   Like      Feedback     Apache POI   get first row of xls



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus