0

enter image description hereI am trying to generate excel file for displaying TestNG report into excel sheet.

For that I created simple program for creating excel sheet and display static data, but it's displaying error

enter image description here

11
  • what's error ?? Commented Dec 15, 2016 at 9:43
  • please check screenshot
    – Rutvi Soni
    Commented Dec 15, 2016 at 9:46
  • image is not visible :( Commented Dec 15, 2016 at 11:01
  • please check now
    – Rutvi Soni
    Commented Dec 15, 2016 at 11:29
  • Please show your reference jar files. Also show your import statement
    – Sagar007
    Commented Dec 15, 2016 at 11:33

1 Answer 1

0

I am following this steps and it is running fine.

1. Need below jar files :

  • poi-3.9-20121203.jar
  • poi-ooxml-3.9-20121203.jar
  • poi-ooxml-schemas-3.9-20121203.jar
  • dom4j-1.6.1.jar
  • xmlbeans-2.3.0.jar

2. Use JRE 7 and Higher

3. Write following code for it as under :

import java.io.File;

import java.io.FileOutputStream;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class WriteData
{
    public static void main(String args[])
    {
        try
        {
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet sh1 = wb.createSheet("Sheet1");
            Row row = sh1.createRow(0);
            Cell cell = row.createCell(0);
            cell.setCellValue("Selenium");
            try
            {
                //Write the workbook in file system
                FileOutputStream out = new FileOutputStream(new File("E:\\Data.xls"));
                wb.write(out);
                out.close();
                System.out.println("written successfully on disk.");
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

Note : Do not use jxl jar and imports.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.