//Download Apache Poi Jar from https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-4.0.1-20181203.zip
2. Add in eclipse project buildpath ( all the jars from all the folders after extraction)
3.Try below code
package dummyarti; //created a new package
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class PoiData {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//read the excel in fr object
FileInputStream fr=new FileInputStream("D:\\TstArea\\data.xlsx");
//passed the excel to workbook
XSSFWorkbook wb=new XSSFWorkbook(fr);
XSSFSheet ws=wb.getSheet("Sheet1") ;
//Created reference to first row .Counting starts from 0
XSSFRow row=ws.createRow(0);
//0 below indicated first column
XSSFCell cell = row.createCell(0);
//writes to 0,0 cell
cell.setCellValue("SoftwareTestingMaterial.com");
//Saves and closes
FileOutputStream out = new FileOutputStream(new File("D:\\TstArea\\data.xlsx"));
wb.write(out);
wb.close();
}
}
2. Add in eclipse project buildpath ( all the jars from all the folders after extraction)
3.Try below code
package dummyarti; //created a new package
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class PoiData {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//read the excel in fr object
FileInputStream fr=new FileInputStream("D:\\TstArea\\data.xlsx");
//passed the excel to workbook
XSSFWorkbook wb=new XSSFWorkbook(fr);
XSSFSheet ws=wb.getSheet("Sheet1") ;
//Created reference to first row .Counting starts from 0
XSSFRow row=ws.createRow(0);
//0 below indicated first column
XSSFCell cell = row.createCell(0);
//writes to 0,0 cell
cell.setCellValue("SoftwareTestingMaterial.com");
//Saves and closes
FileOutputStream out = new FileOutputStream(new File("D:\\TstArea\\data.xlsx"));
wb.write(out);
wb.close();
}
}
No comments:
Post a Comment