0

I have been testing an application where i have to write a set of results to the excel file, the values are taken from the script. But the problem is that first I have to set the column headings like "Sl No" and "Name" after that I have to print the values against the particular cells. The thing is that am not able to write the results under the particular box.

I am new to apache poi. Can anyone help me with this issue.

Code for setting the excel and headings are shown below,

String FileName = "C://Users//Desktop//filename.xlsx";
XSSFWorkbook workBook = new XSSFWorkbook();
XSSFSheet sheet = workBook.createSheet("Distributor");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Sl No");
Cell cell2 = row.createCell(1);
cell2.setCellValue("Name");
FileOutputStream outputStream = new FileOutputStream(new File(FileName));
workBook.write(outputStream);
outputStream.close();
kripindas
  • 480
  • 2
  • 7
  • 21
  • 2
    Not clear where your problem is. You know how to create a `Row`. You also know how to create `Cell`s in that row. So after row 1 create row 2: `row = sheet.createRow(1);`, then create the first cell in that row: `cell = row.createCell(0);` and write the first si no into that, then create the second cell in that row: `cell = row.createCell(1);` and write the first name into that then so on for all needed rows. Btw.: `Cell cell2` is not necessary. You can use `cell` for all cells and `row` for all rows. – Axel Richter Jan 13 '17 at 06:00
  • You should probably read up a bit first and then ask more specific questions. I found the guide at http://poi.apache.org/spreadsheet/quick-guide.html quite helpful to find out how to do certain things with Apache POI – centic Jan 13 '17 at 07:24

0 Answers0