User Guide EasyXLS Basics Import files Import Excel file to ResultSet in Java
Import Excel file to ResultSet in Java EasyXLS™ library allows you to import Excel data to ResultSet. The data can be imported from an Excel sheet or from the active Excel sheet. The entire sheet data, or only data from ranges of cells, can be imported. EasyXLS can be successfully used to also import large Excel files having big volume of data with fast importing time.
Source code sample The below example shows how to import Excel to ResultSet in Java and Coldfusion.
ExcelDocument workbook = new ExcelDocument();
FileInputStream file = new FileInputStream("C:\\Samples\\Tutorial09.xlsx" );
ResultSet resultSet = workbook.easy_ReadXLSXActiveSheet_AsResultSet(file);
int columnCount = resultSet.getMetaData().getColumnCount();
int row = 0;
while (resultSet.next()){
for (int column=1; column < columnCount+1; column++)
System.out.println("At row " + (row + 1) + ", column " + (column) +
" the value is '" + resultSet.getString(column) + "'" );
row++;
}
Click here to see Continuous Code Listing
<cfobject type ="java" class ="EasyXLS.ExcelDocument" name ="workbook" action ="CREATE" >
<cfset rs = workbook.easy_ReadXLSXActiveSheet_AsResultSet("C:\Samples\Tutorial09.xlsx")>
<cfset sError = workbook.easy_getError()>
<CFIF (sError IS "" )>
<cfoutput>
<cfset row = 0>
<cfloop condition ="#rs.next()#" >
<cfset columnCount = rs.getMetaData().getColumnCount()>
<cfloop from ="1" to ="#columnCount-1#" index ="column" >
<cfoutput>
At row #evaluate(row + 1)#, column #evaluate(column + 1)#
the value is '#rs.getString(JavaCast("int",column))#'<br>
</cfoutput>
</cfloop>
<cfset row = row + 1>
</cfloop>
</cfoutput>
<CFELSE>
<cfoutput>
Error encountered: #sError#
</cfoutput>
</CFIF>
Click here to see Continuous Code Listing
This screen shot shows the imported data from Excel sheet into ResultSet.
Import Excel file having one sheet to ResultSet Importing the Excel file data to ResultSet, if the Excel file has only one sheet, is the easiest approach. The Excel data can be imported with one single line of code using: - ExcelDocument.easy_ReadXLSXActiveSheet_AsResultSet method for XLSX file - ExcelDocument.easy_ReadXLSBActiveSheet_AsResultSet method for XLSB file - ExcelDocument.easy_ReadXLSActiveSheet_AsResultSet method for XLS file The above code sample shows how to achieve this goal.
Import Excel file having multiple sheets to ResultSet There are three approaches for importing data from an Excel file with multiple sheets. I. Usually the first sheet is the active sheet inside an Excel file. If this is your case or if you are importing data from another active sheet use: - ExcelDocument.easy_ReadXLSXActiveSheet_AsResultSet method for XLSX file - ExcelDocument.easy_ReadXLSBActiveSheet_AsResultSet method for XLSB file - ExcelDocument.easy_ReadXLSActiveSheet_AsResultSet method for XLS file II. For importing data from an Excel sheet and the name of the sheet is known, EasyXLS recommends the use of: - ExcelDocument.easy_ReadXLSXSheet_AsResultSet method for XLSX file - ExcelDocument.easy_ReadXLSBSheet_AsResultSet method for XLSB file - ExcelDocument.easy_ReadXLSSheet_AsResultSet method for XLS file III. For importing data from an Excel sheet and the name of the sheet is not known, the first step is to find the sheet by reading the Excel file using: - ExcelDocument.easy_LoadXLSXFile method for XLSX file - ExcelDocument.easy_LoadXLSBFile method for XLSB file - ExcelDocument.easy_LoadXLSFile method for XLS file Then, import the sheet data in ResultSet using ExcelDocument.easy_ReadExcelWorksheet_AsResultSet method.
Import range of Excel cells to ResultSet EasyXLS enables you to import Excel data to ResultSet either from the entire sheet or from a range of cells. Importing only a range of cells is a very useful option especially for large Excel files because it reduces the speed of the import process. In order to import multiple cell ranges at once from Excel sheet, the range parameter must be passed to the method as union of ranges (multiple ranges separated by comma). All the methods that allow importing Excel to ResultSet have parameters that permit importing only ranges of cells.
Import XLSX, XLSB, XLSM and XLS files to ResultSet This code sample shows how to import XLSX file to ResultSet. Similarly, you can import XLSM, XLSB, XLS files to ResultSet using: - ExcelDocument.easy_ReadXLSXActiveSheet_AsResultSet or ExcelDocument.easy_ReadXLSXSheet_AsResultSet method for XLSX and XLSM files - ExcelDocument.easy_ReadXLSBActiveSheet_AsResultSet or ExcelDocument.easy_ReadXLSBSheet_AsResultSet method for XLSB files - ExcelDocument.easy_ReadXLSActiveSheet_AsResultSet or ExcelDocument.easy_ReadXLSSheet_AsResultSet method for XLS files
Getting started with EasyXLS Excel library To download the trial version of EasyXLS Excel Library, press the below button:
If you already own a license key, you may login and download EasyXLS from your account. After installation, you will need to create a Java project and add EasyXLS.jar to external libraries.
Available for: Professional, Excel Reader