Five jars are needed to run this:-
1. xmlbeans-2.3.0
2.poi-ooxml-3.5-FINAL
3.poi-3.5-FINAL
4.ooxml-schemas-1.0
5.dom4j-1.6.1(1)
XSSF is used to read .xlsx File,while HSSF for .xls
package com.readindExcelusingXSSF;
import java.io.FileInputStream;
import java.util.Iterator;
import java.util.Vector;
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 ExcelXLSX {
/* @HELP
@class: ExcelXLSX
@Singleton Class(if any): nil
@ constructor(if any): given the name of xlsx file and display method is called, ExcelXLSX()
@methods: Main method,Vector readDataExcelXLSX(String fileName),displayDataExcelXLSX(Vector vectorData)
@parameter: respective methods have their own parameters
@notes: reading excel file ie .xlsx using xssf with added five jars of it
@returns: All respective methods have their return types
@END
*/
private Vector vectorDataExcelXLSX = new Vector();
public ExcelXLSX() {
String excelXLSXFileName = "D:/Test_Config.xlsx";
vectorDataExcelXLSX = readDataExcelXLSX(excelXLSXFileName);
displayDataExcelXLSX(vectorDataExcelXLSX);
}
public static Vector readDataExcelXLSX(String fileName) {
/* @HELP
@class: ExcelXLSX
@method: readDataExcelXLSX()
@parameter:String fileName
@notes: reading xlsx and retriving in a vector
@returns: vector
@END
*/
Vector vectorData = new Vector();
try {
FileInputStream fileInputStream = new FileInputStream(fileName);
XSSFWorkbook xssfWorkBook = new XSSFWorkbook(fileInputStream);
// Read data at sheet 0
XSSFSheet xssfSheet = xssfWorkBook.getSheetAt(0);
Iterator rowIteration = xssfSheet.rowIterator();
// Looping every row at sheet 0
while (rowIteration.hasNext()) {
XSSFRow xssfRow = (XSSFRow) rowIteration.next();
Iterator cellIteration = xssfRow.cellIterator();
Vector vectorCellEachRowData = new Vector();
// Looping every cell in each row at sheet 0
while (cellIteration.hasNext())
{
XSSFCell xssfCell = (XSSFCell) cellIteration.next();
vectorCellEachRowData.addElement(xssfCell);
}
vectorData.addElement(vectorCellEachRowData);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return vectorData;
}
public static void displayDataExcelXLSX(Vector vectorData) {
/* @HELP
@class: ExcelXLSX
@method: displayDataExcelXLSX()
@parameter:Vector vectorData
@notes: display the vector to console
@returns: nil
@END
*/
// Looping every row data in vector
for(int i=1; i<vectorData.size(); i++) {
Vector vectorCellEachRowData = (Vector) vectorData.get(i);
// looping every cell in each row
for(int j=0; j<vectorCellEachRowData.size(); j++) {
System.out.print(vectorCellEachRowData.get(j).toString()+"\t\t ");
}
System.out.println("");
}
}
public static void main(String[] argas)
{
/* @HELP
@class: ExcelXLSX
@method: main()
@parameter:String Array
@notes:object creation to call constructor
@returns: nil
@END
*/
new ExcelXLSX();
}
}
Two Stones Is Top Web Design Company In Coimbatore India Crafting Static And CMS Websites In Html, Wordpress Website Design Coimbatore With User Experience To Generate Website Leads In Coimbatore
ReplyDelete[URL=https://twostones.co/web-design-company-in-coimbatore/]Website Design Coimbatore[/URL]
Two Stone Is Leading SEO Companies In Coimbatore India, Providing Best Search Engine Optimization Service In Coimbatore. SEM & SEO Service Provider In Coimbatore
[URL=https://twostones.co/seo-company-in-coimbatore/]SEO Company In Coimbatore[/URL]
Two Stones, A Leading Digital Marketing Company In Coimbatore, Digital Marketing Agency & Expertised In SEO, Branding, SMO, PPC, SMM (Social Media Marketing), SEM (Search Engine Marketing) In Coimbatore India, Best Digital Marketing Companies In Coimbatore
[URL=https://twostones.co/digital-marketing-company-in-coimbatore/]Digital Marketing Company In Coimbatore[/URL]
Two Stones Is A Leading Web Development Company In Coimbatore. Best Web Development In Coimbatore Indai We Develop Web Apps In ASP.NET, Java, PHP, Django, Python, Node.js, Ruby, C#
[URL=https://twostones.co/web-development-company-coimbatore/]Web Development Company In Coimbatore[/URL]
Mobile Application Development In Coimbatore
[URL=https://twostones.co/mobile-app-development-company-in-coimbatore/]Mobile Application Development In Coimbatore[/URL]