I have a sample of Excel data that needs to be read and store in the database. Example:
Code | BO1 | BO2 | BO3 | .....
10001 | 200.00 | 400.00 | 0.00 | .....
10002 | 0.00 | 100.00 | 500.00 | .....
I have tried to use Apache POI in reading data by row. But how do I get the Name and the amount from the column at the same time? Something like this
10001,BO1,200.00
10001,BO2,400.00
10001,BO3,0.00
10002,BO1,0.00
10002,BO2,100.00
10002,BO3,500.00
Any help would be appreciated. Thanks
FileInputStream fis = (FileInputStream) files.getInputStream();
POIFSFileSystem fs = new POIFSFileSystem(fis);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Row row;
for(int i=4; i<=sheet.getLastRowNum(); i++)
{
row = sheet.getRow(i);
String gl;
Cell cell1 = row.getCell(0);
if(cell1.getCellType()==Cell.CELL_TYPE_NUMERIC)
{
gl = String.valueOf(cell1.getNumericCellValue()).replace(".0", "").trim();
}
else
{
gl = cell1.getStringCellValue();
}
write.println("<p>"+gl+"</p>");
}