i managed to write the data to a single column.
My req is to write the data to the next adjacent column without overriding the data in the fist column.
Any help?
InputStream inp;
try {
inp = new FileInputStream("D:\\test.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = null;
Cell c = null;
int rowNum=0;
Set<String> keySet = new HashSet<String>();
keySet = tushMap.keySet();
for (Entry<String, String> entry : tushMap.entrySet()) {
row=sheet.createRow((short) (sheet.getLastRowNum() + 1));
System.out.println((short) (sheet.getLastRowNum() + 1));
c = row.createCell(0);
c.setCellValue("fff");
System.out.println("fff");
System.out.println(entry.getKey() + "/" + entry.getValue());
rowNum++;
}
FileOutputStream fileOut = new FileOutputStream("D:\\test.xls");
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
This is the code written to populate the 1st column.
Populating the second column overrides the fist 1..
Pls suggest some solution..
Thanks in advance.
To get the data side by side get the last row outside the loop and save it as the begening row. Keep a counter for which row you are editing inside the loop. If the row is null create the row.
EDIT:
I am getting the desierd output using this
Output