Tuesday, January 12, 2016

Datatable: How to open or access excel using selenium -- using Apache POI package


1/12/2016

source: http://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-3.13-20150929.zip

Basic java code cannot access Excel directly we need import package poi.apache.org

The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate.

From stackoverflow:

1. You can use this api to read excel rows from java: http://jexcelapi.sourceforge.net/ The tutorial is great and can be found here: http://www.andykhan.com/jexcelapi/tutorial.html

2. There are many API's in java available to read data from Excel.
  1. JExcelApi.
  2. POI
3. Work Around
Save Excel as CSV files (in case you don't want to use any external API)and read them normally as a text file. But use Comma as Separator.
Check this link for more information: read/write excel file in java
I hope this helps :-)
Apache POI to access Excel http://poi.apache.org/spreadsheet/index.html


looks like jar files are available in:

http://apache.mirrors.hoobly.com/poi/release/bin/poi-bin-3.13-20150929.zip

The table below synopsizes the comparative features of POI's Spreadsheet API:
Spreadsheet API Feature Summary
Spreadsheet API Feature Summary




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

import java.io.IOException;

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

public class connectingtoExcelandextractingdata {

public static void main(String[] args) throws IOException {

XSSFWorkbook srcBook = new XSSFWorkbook("c/prop.xlsx");     
        XSSFSheet sourceSheet = srcBook.getSheetAt(0); 

   
}

}

No comments:

Post a Comment