
Hi All I am developing a java application whre we upload a excel file in to database and all excel value should import in to the database column. I am using below logic for inserting value. it shwoing some garbaze value.
my code is:
package import java.io.FileInputStream; import java.util.Iterator; import java.util.Vector;
import org.apache.poi.hssf.usermodel.HSSFCell; 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;
public class ReadExcelFile {
public static void main(String[] args) {
String fileName = "C:\\hhh.xls";
Vector dataHolder = ReadCSV(fileName);
printCellDataToConsole(dataHolder);
}
public static Vector ReadCSV(String fileName) {
Vector cellVectorHolder = new Vector();
try {
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
while (rowIter.hasNext()) {
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector = new Vector();
while (cellIter.hasNext()) {
HSSFCell myCell = (HSSFCell) cellIter.next();
cellStoreVector.addElement(myCell);
}
cellVectorHolder.addElement(cellStoreVector);
}
} catch (Exception e) {
e.printStackTrace();
}
return cellVectorHolder;
}
private static void printCellDataToConsole(Vector dataHolder) {
for (int i = 0; i < dataHolder.size(); i++) {
Vector cellStoreVector = (Vector) dataHolder.elementAt(i);
for (int j = 0; j < cellStoreVector.size(); j++) {
HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
String stringCellValue = myCell.toString();
System.out.print(stringCellValue + "\t");
}
System.out.println();
}
}
}
but it showing following output:
org.apache.poi.hssf.usermodel.HSSFCell@bfc8e0 org.apache.poi.hssf.usermodel.HSSFCell@11d0a4f
org.apache.poi.hssf.usermodel.HSSFCell@18fd984 org.apache.poi.hssf.usermodel.HSSFCell@111a775
org.apache.poi.hssf.usermodel.HSSFCell@91cee org.apache.poi.hssf.usermodel.HSSFCell@4a63d8
it is not showing real excel sheet value.
please suggest good way to solve this problem.

sorry if it's too late, try myCell.getStringCellValue() instead of myCell.toString()
That way you are only writing the object in memory.

sorry if it's too late, try myCell.getStringCellValue() instead of myCell.toString()
That way you are only writing the object in memory
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.