Tuesday, February 28, 2012

JAVA: Reading Excel File

This article will teach you on how to open and read Microsoft Excel 2010 file using Apache POI.

download Apache POI jar file here:

Below are the following code:


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TestExcel {
     private static String localPath;
     private static String fileName;
     /**
       * @param args
       */
     public static void main(String[] args) {
         // TODO Auto-generated method stub
 InputStream inputStream = null;
 try {
      System.out.println("Reading Excel File: " +
                                 localPath + "/" + fileName);
      InputStream = new FileInputStream(localPath + "/" + fileName);
              XSSFWorkbook workBook = new XSSFWorkbook (inputStream);
              XSSFSheet sheet = workBook.getSheetAt(0);
              System.out.println("Getting sheet... ");
      int cellCount = 0;
      System.out.println("Cell counting... ");
      for(int i=0; i < 1; i++){
           XSSFRow rowHeader = sheet.getRow(i);
              cellCount = rowHeader.getLastCellNum();
      }
      System.out.println("cellcount: " + cellCount);
        for(int i=1; i < sheet.getLastRowNum() + 1; i++){
          XSSFRow row = sheet.getRow(i);
  System.out.println(row.getCell((short) 2));
      }
  } catch (FileNotFoundException e) {
      System.out.println(e.getMessage());
  } catch (IOException e) {
      System.out.println(e.getMessage());
  } 
     }
}

Monday, February 27, 2012

JAVA: Listing files


This article will teach you on how to get files on a specified directory and displaying its file name and size. Below are the following code:

import java.io.File;
public class TestFile {
    public static void main(String args[]) throws Exception {
          File folder = new File("D:/some folders");
          File[] listOfFiles = folder.listFiles();
          for (int i = 0; i < listOfFiles.length; i++) {
               if (listOfFiles[i].isFile()) {
                    System.out.println(listOfFiles[i].getName() 
                    + "," + listOfFiles[i].length() / 1024 + " KB");
               }
          }
     }
}

Wednesday, February 15, 2012

Last August 2011, I posted about the "A Perfect Gift from GOD"  and now with only one month to go and my baby will be born. My wife and I decided to have our baby named as Stephany Jillian Benito. Everyday I feel the excitement every time I see her moved in her mother's womb. I prayed for a normal delivery and a good health for my baby. Here are some pictures of us taken last January 2012.





See soon baby Stephany Jillian Benito...

Tuesday, February 14, 2012

It has been quite long time since the last I posted something on this blog of mine. I have been busy at work lately. Today I will resume blogging... Watch out guys! Happy Valentines Day to all...
Related Posts Plugin for WordPress, Blogger...

Blog List