Hello again,
Borrowing the code sample from http://forum.java.sun.com/thread.jspa?threadID=655422&messageID=3893444#3893444, even asked the question there, BUT re-post as a new one here based on someone's reply........
Questions: After getting the cell value by using POI, is there any way to get that cell's column name ???
Thanks a lot for your time!
..........................................................................
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
class rowCount {
public static void main(String args[]) {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));
HSSFWorkbook wb = new HSSFWorkbook(fs);
System.out.println("Number of sheets: " + wb.getNumberOfSheets());
HSSFSheet sheet = wb.getSheetAt(0);
int numberOfRows = sheet.getLastRowNum();
System.out.println("LastRowNumber in sheet0: " + sheet.getLastRowNum());
for (int i = 0; i <= numberOfRows; i++) {
HSSFRow row = sheet.getRow(i);
int cellCount = row.getLastCellNum();
System.out.println("RowNumber" + i);
System.out.println("Number of cells in each row" + cellCount);
for (int j = 0; j < cellCount; j++) {
HSSFCell cell = row.getCell((short) j);
if (cell == null) {
System.out.println("No cell Value");
continue;
}
if (j == 2){
//System.out.println("cell");
System.out.println("RowNumber" + i);
System.out.println("cell value: "+ cell.getStringCellValue() + "\n");
}
}
}
} catch (IOException ioe) {
// TODO: handle exception
System.out.println("IOException" + ioe.getMessage());
}
}
}