EasyXLS™ library allows you to read Excel formulas, export Excel files with formulas and calculate Excel formulas.
Formulas are mathematical expressions that allow calculations for sheets values.
EasyXLS™ component provides all the functions supported by Excel as far as formulas are concerned. It provides arithmetic, logical and unary operators, formulas with numbers, dates and strings, formulas with cell references, formulas with cell ranges, formulas with names and with arrays.
EasyXLS™ library can be integrated in:
- ASP.NET web pages - Windows applications - Windows Forms (WinForms) - Console applications - Windows service applications - ASP.NET MVC web applications - PHP and ASP web pages - Java applications
Range operator, which produces one reference to all the cells between two references, including the two references. Note: This is the: operator from Excel
,
Union operator, which combines multiple references into one reference
|
Intersection operator, which produces one reference to cells common to the two references. Note: This is the space operator from Excel
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Add a sheet
workbook.easy_addWorksheet("Formula");
// Get the table of data for the sheet
ExcelTable xlsTable =
((ExcelWorksheet)workbook.easy_getSheet("Formula")).easy_getExcelTable();
// Add data in cells and set the formula
xlsTable.easy_getCell("A1").setValue("1");
xlsTable.easy_getCell("A2").setValue("2");
xlsTable.easy_getCell("A3").setValue("3");
xlsTable.easy_getCell("A4").setValue("4");
xlsTable.easy_getCell("A6").setValue("=SUM(A1:A4)");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel with formulas.xlsx");
' Create an instance of the class that exports Excel filesDim workbook As New ExcelDocument
' Add a sheet
workbook.easy_addWorksheet("Formula")
' Get the table of data for the sheetDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheet("Formula")
Dim xlsTable = xlsFirstTab.easy_getExcelTable()
' Add data in cells and set the formula
xlsTable.easy_getCell("A1").setValue("1")
xlsTable.easy_getCell("A2").setValue("2")
xlsTable.easy_getCell("A3").setValue("3")
xlsTable.easy_getCell("A4").setValue("4")
xlsTable.easy_getCell("A6").setValue("=SUM(A1:A4)")
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Excel with formulas.xlsx")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Add a sheet
workbook->easy_addWorksheet_2("Formula");
// Get the table of data for the sheet
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheet("Formula");
EasyXLS::IExcelTablePtr xlsTable = xlsFirstTab->easy_getExcelTable();
// Add data in cells and set the formula
xlsTable->easy_getCell_2("A1")->setValue("1");
xlsTable->easy_getCell_2("A2")->setValue("2");
xlsTable->easy_getCell_2("A3")->setValue("3");
xlsTable->easy_getCell_2("A4")->setValue("4");
xlsTable->easy_getCell_2("A6")->setValue("=SUM(A1:A4)");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel with formulas.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Add a sheet
workbook->easy_addWorksheet("Formula");
// Get the table of data for the sheet
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheet("Formula"));
ExcelTable ^xlsTable = xlsFirstTab->easy_getExcelTable();
// Add data in cells and set the formula
xlsTable->easy_getCell("A1")->setValue("1");
xlsTable->easy_getCell("A2")->setValue("2");
xlsTable->easy_getCell("A3")->setValue("3");
xlsTable->easy_getCell("A4")->setValue("4");
xlsTable->easy_getCell("A6")->setValue("=SUM(A1:A4)");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Excel with formulas.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Add a sheet
workbook.easy_addWorksheet("Formula");
// Get the table of data for the sheet
ExcelTable xlsTable =
((ExcelWorksheet)workbook.easy_getSheet("Formula")).easy_getExcelTable();
// Add data in cells and set the formula
xlsTable.easy_getCell("A1").setValue("1");
xlsTable.easy_getCell("A2").setValue("2");
xlsTable.easy_getCell("A3").setValue("3");
xlsTable.easy_getCell("A4").setValue("4");
xlsTable.easy_getCell("A6").setValue("=SUM(A1:A4)");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel with formulas.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Add a sheet
$workbook->easy_addWorksheet_2("Formula");
// Get the table of data for the sheet
$xlsTable = $workbook->easy_getSheet("Formula")->easy_getExcelTable();
// Add data in cells and set the formula
$xlsTable->easy_getCell_2("A1")->setValue("1");
$xlsTable->easy_getCell_2("A2")->setValue("2");
$xlsTable->easy_getCell_2("A3")->setValue("3");
$xlsTable->easy_getCell_2("A4")->setValue("4");
$xlsTable->easy_getCell_2("A6")->setValue("=SUM(A1:A4)");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel with formulas.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create a sheet
$workbook->easy_addWorksheet("Formula");
// Get the table of data for the sheet, add data in sheet and the formula
$xlsTable = $workbook->easy_getSheet("Formula")->easy_getExcelTable();
$xlsTable->easy_getCell("A1")->setValue("1");
$xlsTable->easy_getCell("A2")->setValue("2");
$xlsTable->easy_getCell("A3")->setValue("3");
$xlsTable->easy_getCell("A4")->setValue("4");
$xlsTable->easy_getCell("A6")->setValue("=SUM(A1:A4)");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Excel with formulas.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Add a sheet
workbook.easy_addWorksheet_2("Formula")
' Get the table of data for the sheetSet xlsTable = workbook.easy_getSheet("Formula").easy_getExcelTable()
' Add data in cells and set the formula
xlsTable.easy_getCell_2("A1").setValue("1")
xlsTable.easy_getCell_2("A2").setValue("2")
xlsTable.easy_getCell_2("A3").setValue("3")
xlsTable.easy_getCell_2("A4").setValue("4")
xlsTable.easy_getCell_2("A6").setValue("=SUM(A1:A4)")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel with formulas.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Add a sheet
workbook.easy_addWorksheet_2 ("Formula")
' Get the table of data for the sheetSet xlsTable = workbook.easy_getSheet("Formula").easy_getExcelTable()
' Add data in cells and set the formula
xlsTable.easy_getCell_2("A1").setValue ("1")
xlsTable.easy_getCell_2("A2").setValue ("2")
xlsTable.easy_getCell_2("A3").setValue ("3")
xlsTable.easy_getCell_2("A4").setValue ("4")
xlsTable.easy_getCell_2("A6").setValue ("=SUM(A1:A4)")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel with formulas.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Add a sheet
workbook.easy_addWorksheet_2("Formula")
' Get the table of data for the sheetSet xlsTable = workbook.easy_getSheet("Formula").easy_getExcelTable()
' Add data in cells and set the formula
xlsTable.easy_getCell_2("A1").setValue ("1")
xlsTable.easy_getCell_2("A2").setValue ("2")
xlsTable.easy_getCell_2("A3").setValue ("3")
xlsTable.easy_getCell_2("A4").setValue ("4")
xlsTable.easy_getCell_2("A6").setValue ("=SUM(A1:A4)")
' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Excel with formulas.xlsx")
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Add a sheet --><cfset ret = workbook.easy_addWorksheet("Formula")><!-- Get the table of data for the sheet --><cfset xlsTable = workbook.easy_getSheet("Formula").easy_getExcelTable()><!-- Add data in cells and set the formula --><cfset xlsTable.easy_getCell("A1").setValue("1")><cfset xlsTable.easy_getCell("A2").setValue("2")><cfset xlsTable.easy_getCell("A3").setValue("3")><cfset xlsTable.easy_getCell("A4").setValue("4")><cfset xlsTable.easy_getCell("A6").setValue("=SUM(A1:A4)")><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel with formulas.xlsx")>
.NET:# Create an instance of the class that exports Excel files
workbook = ExcelDocument()
# Create a sheet
workbook.easy_addWorksheet("Formula")
# Get the table of data for the sheet, add data in sheet and the formula
xlsTable = workbook.easy_getSheet("Formula").easy_getExcelTable()
xlsTable.easy_getCell("A1").setValue("1")
xlsTable.easy_getCell("A2").setValue("2")
xlsTable.easy_getCell("A3").setValue("3")
xlsTable.easy_getCell("A4").setValue("4")
xlsTable.easy_getCell("A6").setValue("=SUM(A1:A4)")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel with formulas.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that exports Excel files
workbook = gateway.jvm.ExcelDocument()
# Create a sheet
workbook.easy_addWorksheet("Formula")
# Get the table of data for the sheet, add data in sheet and the formula
xlsTable = workbook.easy_getSheet("Formula").easy_getExcelTable()
xlsTable.easy_getCell("A1").setValue("1")
xlsTable.easy_getCell("A2").setValue("2")
xlsTable.easy_getCell("A3").setValue("3")
xlsTable.easy_getCell("A4").setValue("4")
xlsTable.easy_getCell("A6").setValue("=SUM(A1:A4)")
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Excel with formulas.xlsx")
Click here to see Continuous Code Listing
The screen shot below represents the exported Excel file with formulas generated by the code sample above. The formula represents the sum of the cell values from A1 to A4. The result of the formula is displayed in cell A6.
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formula.xlsx");
// Get the worksheet with formula
ExcelWorksheet xlsWorksheet = (ExcelWorksheet)workbook.easy_getSheet("Formula sheet");
// Get the table of data for the sheet
ExcelTable xlsTable = xlsWorksheet.easy_getExcelTable();
// Get formula expressionString formula = xlsTable.easy_getCell("A6").getValue();
Console.WriteLine("The formula is: " + formula);
' Create an instance of the class that imports Excel filesDim workbook As New ExcelDocument()
' Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formula.xlsx")
' Get the worksheet with formulaDim xlsWorksheet As ExcelWorksheet = workbook.easy_getSheet("Formula sheet")
' Get the table of data for the sheetDim xlsTable = xlsWorksheet.easy_getExcelTable()
' Get formula expressionDim formula = xlsTable.easy_getCell("A6").getValue()
Console.WriteLine("The formula is: " + formula)
C++// Create an instance of the class that imports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Load Excel file
workbook->easy_LoadXLSXFile("C:\\Samples\\Formula.xlsx");
// Get the worksheet with formula
EasyXLS::IExcelWorksheetPtr xlsWorksheet =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheet("Formula sheet");
// Get the table of data for the sheet
EasyXLS::IExcelTablePtr xlsTable = xlsWorksheet->easy_getExcelTable();
// Get formula expression
_bstr_t formula = xlsTable->easy_getCell_2("A6")->getValue();
printf("The formula is: " + formula);
C++.NET// Create an instance of the class that imports Excel files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Load Excel file
workbook->easy_LoadXLSXFile("C:\\Samples\\Formula.xlsx");
// Get the worksheet with formula
ExcelWorksheet ^xlsWorksheet =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheet("Formula sheet"));
// Get the table of data for the sheet
ExcelTable ^xlsTable = xlsWorksheet->easy_getExcelTable();
// Get formula expressionString ^formula = xlsTable->easy_getCell("A6")->getValue();
Console::Write("The formula is: " + formula);
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formula.xlsx");
// Get the worksheet with formula
ExcelWorksheet xlsWorksheet = (ExcelWorksheet)workbook.easy_getSheet("Formula sheet");
// Get the table of data for the sheet
ExcelTable xlsTable = xlsWorksheet.easy_getExcelTable();
// Get formula expressionString formula = xlsTable.easy_getCell("A6").getValue();
System.out.println("The formula is: " + formula);
.NET:// Create an instance of the class that imports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Load Excel file
$workbook->easy_LoadXLSXFile("C:\Samples\Formula.xlsx");
// Get the worksheet with formula
$xlsWorksheet = $workbook->easy_getSheet("Formula sheet");
// Get the table of data for the sheet
$xlsTable = $xlsWorksheet->easy_getExcelTable();
// Get formula expression
$formula = $xlsTable->easy_getCell_2("A6")->getValue();
echo"The formula is: " . $formula;
Java:// Create an instance of the class that imports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Load Excel file
$workbook->easy_LoadXLSXFile("C:\Samples\Formula.xlsx");
// Get the worksheet with formula
$xlsWorksheet = $workbook->easy_getSheet("Formula sheet");
// Get the table of data for the sheet
$xlsTable = $xlsWorksheet->easy_getExcelTable();
// Get formula expression
$formula = $xlsTable->easy_getCell("A6")->getValue();
echo"The formula is: " . $formula;
' Create an instance of the class that imports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Formula.xlsx")
' Get the worksheet with formulaset xlsWorksheet = workbook.easy_getSheet("Formula sheet")
' Get the table of data for the sheetset xlsTable = xlsWorksheet.easy_getExcelTable()
' Get formula expression
formula = xlsTable.easy_getCell_2("A6").getValue()
response.write("The formula is: " + formula)
' Create an instance of the class that imports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile ("C:\Samples\Formula.xlsx")
' Get the worksheet with formulaSet xlsWorksheet = workbook.easy_getSheet("Formula sheet")
' Get the table of data for the sheetSet xlsTable = xlsWorksheet.easy_getExcelTable()
' Get formula expression
formula = xlsTable.easy_getCell_2("A6").getValue()
Me.Label1.Caption = Me.Label1.Caption & vbCrLf & "The formula is: " & formula
' Create an instance of the class that imports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Formula.xlsx")
' Get the worksheet with formulaSet xlsWorksheet = workbook.easy_getSheet("Formula sheet")
' Get the table of data for the sheetSet xlsTable = xlsWorksheet.easy_getExcelTable()
' Get formula expression
formula = xlsTable.easy_getCell_2("A6").getValue()
WScript.StdOut.Write("The formula is: " + formula)
<!-- Create an instance of the class that imports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Load Excel file --><cfset ret = workbook.easy_LoadXLSXFile("C:\Samples\Formula.xlsx")><!-- Get the worksheet with formula --><cfset ret = xlsWorksheet = workbook.easy_getSheet("Formula sheet")><!-- Get the table of data for the sheet --><cfset ret = xlsTable = xlsWorksheet.easy_getExcelTable()><!-- Get formula expression --><cfset ret = formula = xlsTable.easy_getCell("A6").getValue()><cfoutput>
The formula is: #formula#
</cfoutput>
.NET:# Create an instance of the class that imports Excel files
workbook = ExcelDocument()
# Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formula.xlsx")
# Get the worksheet with formula
xlsWorksheet = workbook.easy_getSheet("Formula sheet")
# Get the table of data for the sheet
xlsTable = xlsWorksheet.easy_getExcelTable()
# Get formula expression
formula = xlsTable.easy_getCell("A6").getValue()
print("The formula is: " + formula)
Java:# Create an instance of the class that imports Excel files
workbook = gateway.jvm.ExcelDocument()
# Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formula.xlsx")
# Get the worksheet with formula
xlsWorksheet = workbook.easy_getSheet("Formula sheet")
# Get the table of data for the sheet
xlsTable = xlsWorksheet.easy_getExcelTable()
# Get formula expression
formula = xlsTable.easy_getCell("A6").getValue()
print("The formula is: " + formula)
Also, the formula value can be read using various methods that allows importing the Excel file to DataSet, ResultSet or List.
EasyXLS supports also array formulas that can be added to cell ranges. The below source code sample shows how to add an array formula on D2:D3 cell range.
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Add a sheet
workbook.easy_addWorksheet("Array formula");
ExcelWorksheet xlsSheet = (ExcelWorksheet)workbook.easy_getSheet("Array formula");
// Get the table of data for the sheet
ExcelTable xlsTable = xlsSheet.easy_getExcelTable();
// Add data in cells
xlsTable.easy_getCell("A1").setValue("Item");
xlsTable.easy_getCell("B1").setValue("Quantity (kg)");
xlsTable.easy_getCell("C1").setValue("Price ($)");
xlsTable.easy_getCell("D1").setValue("Total");
xlsTable.easy_getCell("A2").setValue("Apples");
xlsTable.easy_getCell("B2").setValue("2");
xlsTable.easy_getCell("C2").setValue("4");
xlsTable.easy_getCell("A3").setValue("Plums");
xlsTable.easy_getCell("B3").setValue("6");
xlsTable.easy_getCell("C3").setValue("9");
// Add array formula
xlsSheet.easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
' Create an instance of the class that exports Excel filesDim workbook = New ExcelDocument()
' Add a sheet
workbook.easy_addWorksheet("Array formula")
Dim xlsSheet As ExcelWorksheet = workbook.easy_getSheet("Array formula")
' Get the table of data for the sheetDim xlsTable = xlsSheet.easy_getExcelTable()
' Add data in cells
xlsTable.easy_getCell("A1").setValue("Item")
xlsTable.easy_getCell("B1").setValue("Quantity (kg)")
xlsTable.easy_getCell("C1").setValue("Price ($)")
xlsTable.easy_getCell("D1").setValue("Total")
xlsTable.easy_getCell("A2").setValue("Apples")
xlsTable.easy_getCell("B2").setValue("2")
xlsTable.easy_getCell("C2").setValue("4")
xlsTable.easy_getCell("A3").setValue("Plums")
xlsTable.easy_getCell("B3").setValue("6")
xlsTable.easy_getCell("C3").setValue("9")
' Add array formula
xlsSheet.easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3")
' Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Add a sheet
workbook->easy_addWorksheet_2("Array formula");
EasyXLS::IExcelWorksheetPtr xlsSheet = workbook->easy_getSheet("Array formula");
// Get the table of data for the sheet
EasyXLS::IExcelTablePtr xlsTable = xlsSheet->easy_getExcelTable();
// Add data in cells
xlsTable->easy_getCell_2("A1")->setValue("Item");
xlsTable->easy_getCell_2("B1")->setValue("Quantity (kg)");
xlsTable->easy_getCell_2("C1")->setValue("Price ($)");
xlsTable->easy_getCell_2("D1")->setValue("Total");
xlsTable->easy_getCell_2("A2")->setValue("Apples");
xlsTable->easy_getCell_2("B2")->setValue("2");
xlsTable->easy_getCell_2("C2")->setValue("4");
xlsTable->easy_getCell_2("A3")->setValue("Plums");
xlsTable->easy_getCell_2("B3")->setValue("6");
xlsTable->easy_getCell_2("C3")->setValue("9");
// Add array formula
xlsSheet->easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
C++.NET// Create an instance of the class that exports Excel files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Add a sheet
workbook->easy_addWorksheet("Array formula");
ExcelWorksheet ^xlsSheet = safe_cast<ExcelWorksheet^>(workbook->easy_getSheet("Array formula"));
// Get the table of data for the sheet
ExcelTable ^xlsTable = xlsSheet->easy_getExcelTable();
// Add data in cells
xlsTable->easy_getCell("A1")->setValue("Item");
xlsTable->easy_getCell("B1")->setValue("Quantity (kg)");
xlsTable->easy_getCell("C1")->setValue("Price ($)");
xlsTable->easy_getCell("D1")->setValue("Total");
xlsTable->easy_getCell("A2")->setValue("Apples");
xlsTable->easy_getCell("B2")->setValue("2");
xlsTable->easy_getCell("C2")->setValue("4");
xlsTable->easy_getCell("A3")->setValue("Plums");
xlsTable->easy_getCell("B3")->setValue("6");
xlsTable->easy_getCell("C3")->setValue("9");
// Add array formula
xlsSheet->easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Add a sheet
workbook.easy_addWorksheet("Array formula");
ExcelWorksheet xlsSheet = (ExcelWorksheet)workbook.easy_getSheet("Array formula");
// Get the table of data for the sheet
ExcelTable xlsTable = xlsSheet.easy_getExcelTable();
// Add data in cells
xlsTable.easy_getCell("A1").setValue("Item");
xlsTable.easy_getCell("B1").setValue("Quantity (kg)");
xlsTable.easy_getCell("C1").setValue("Price ($)");
xlsTable.easy_getCell("D1").setValue("Total");
xlsTable.easy_getCell("A2").setValue("Apples");
xlsTable.easy_getCell("B2").setValue("2");
xlsTable.easy_getCell("C2").setValue("4");
xlsTable.easy_getCell("A3").setValue("Plums");
xlsTable.easy_getCell("B3").setValue("6");
xlsTable.easy_getCell("C3").setValue("9");
// Add array formula
xlsSheet.easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Add a sheet
$workbook->easy_addWorksheet_2("Array formula");
$xlsSheet = $workbook->easy_getSheet("Array formula");
// Get the table of data for the sheet
$xlsTable = $xlsSheet->easy_getExcelTable();
// Add data in cells
$xlsTable->easy_getCell_2("A1")->setValue("Item");
$xlsTable->easy_getCell_2("B1")->setValue("Quantity (kg)");
$xlsTable->easy_getCell_2("C1")->setValue("Price ($)");
$xlsTable->easy_getCell_2("D1")->setValue("Total");
$xlsTable->easy_getCell_2("A2")->setValue("Apples");
$xlsTable->easy_getCell_2("B2")->setValue("2");
$xlsTable->easy_getCell_2("C2")->setValue("4");
$xlsTable->easy_getCell_2("A3")->setValue("Plums");
$xlsTable->easy_getCell_2("B3")->setValue("6");
$xlsTable->easy_getCell_2("C3")->setValue("9");
// Add array formula
$xlsSheet->easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
Java:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Add a sheet
$workbook->easy_addWorksheet("Array formula");
$xlsSheet = $workbook->easy_getSheet("Array formula");
// Get the table of data for the sheet
$xlsTable = $xlsSheet->easy_getExcelTable();
// Add data in cells
$xlsTable->easy_getCell("A1")->setValue("Item");
$xlsTable->easy_getCell("B1")->setValue("Quantity (kg)");
$xlsTable->easy_getCell("C1")->setValue("Price ($)");
$xlsTable->easy_getCell("D1")->setValue("Total");
$xlsTable->easy_getCell("A2")->setValue("Apples");
$xlsTable->easy_getCell("B2")->setValue("2");
$xlsTable->easy_getCell("C2")->setValue("4");
$xlsTable->easy_getCell("A3")->setValue("Plums");
$xlsTable->easy_getCell("B3")->setValue("6");
$xlsTable->easy_getCell("C3")->setValue("9");
// Add array formula
$xlsSheet->easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Add a sheet
workbook.easy_addWorksheet_2("Array formula")
set xlsSheet = workbook.easy_getSheet("Array formula")
' Get the table of data for the sheetset xlsTable = xlsSheet.easy_getExcelTable()
' Add data in cells
xlsTable.easy_getCell_2("A1").setValue("Item")
xlsTable.easy_getCell_2("B1").setValue("Quantity (kg)")
xlsTable.easy_getCell_2("C1").setValue("Price ($)")
xlsTable.easy_getCell_2("D1").setValue("Total")
xlsTable.easy_getCell_2("A2").setValue("Apples")
xlsTable.easy_getCell_2("B2").setValue("2")
xlsTable.easy_getCell_2("C2").setValue("4")
xlsTable.easy_getCell_2("A3").setValue("Plums")
xlsTable.easy_getCell_2("B3").setValue("6")
xlsTable.easy_getCell_2("C3").setValue("9")
' Add array formula
xlsSheet.easy_addArrayFormula "D2:D3", "=B2:B3*C2:C3"' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Array formulas.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Add a sheet
workbook.easy_addWorksheet_2("Array formula")
Set xlsSheet = workbook.easy_getSheet("Array formula")
' Get the table of data for the sheetSet xlsTable = xlsSheet.easy_getExcelTable()
' Add data in cells
xlsTable.easy_getCell_2("A1").setValue("Item")
xlsTable.easy_getCell_2("B1").setValue("Quantity (kg)")
xlsTable.easy_getCell_2("C1").setValue("Price ($)")
xlsTable.easy_getCell_2("D1").setValue("Total")
xlsTable.easy_getCell_2("A2").setValue("Apples")
xlsTable.easy_getCell_2("B2").setValue("2")
xlsTable.easy_getCell_2("C2").setValue("4")
xlsTable.easy_getCell_2("A3").setValue("Plums")
xlsTable.easy_getCell_2("B3").setValue("6")
xlsTable.easy_getCell_2("C3").setValue("9")
' Add array formula
xlsSheet.easy_addArrayFormula "D2:D3", "=B2:B3*C2:C3"' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Array formulas.xlsx")
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Add a sheet
workbook.easy_addWorksheet_2("Array formula")
Set xlsSheet = workbook.easy_getSheet("Array formula")
' Get the table of data for the sheetSet xlsTable = xlsSheet.easy_getExcelTable()
' Add data in cells
xlsTable.easy_getCell_2("A1").setValue("Item")
xlsTable.easy_getCell_2("B1").setValue("Quantity (kg)")
xlsTable.easy_getCell_2("C1").setValue("Price ($)")
xlsTable.easy_getCell_2("D1").setValue("Total")
xlsTable.easy_getCell_2("A2").setValue("Apples")
xlsTable.easy_getCell_2("B2").setValue("2")
xlsTable.easy_getCell_2("C2").setValue("4")
xlsTable.easy_getCell_2("A3").setValue("Plums")
xlsTable.easy_getCell_2("B3").setValue("6")
xlsTable.easy_getCell_2("C3").setValue("9")
' Add array formula
xlsSheet.easy_addArrayFormula "D2:D3", "=B2:B3*C2:C3"' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Array formulas.xlsx")
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Add a sheet --><cfset ret = workbook.easy_addWorksheet("Array formula")><cfset xlsSheet = workbook.easy_getSheet("Array formula")><!-- Get the table of data for the sheet --><cfset xlsTable = xlsSheet.easy_getExcelTable()><!-- Add data in cells --><cfset ret = xlsTable.easy_getCell("A1").setValue("Item")><cfset ret = xlsTable.easy_getCell("B1").setValue("Quantity (kg)")><cfset ret = xlsTable.easy_getCell("C1").setValue("Price ($)")><cfset ret = xlsTable.easy_getCell("D1").setValue("Total")><cfset ret = xlsTable.easy_getCell("A2").setValue("Apples")><cfset ret = xlsTable.easy_getCell("B2").setValue("2")><cfset ret = xlsTable.easy_getCell("C2").setValue("4")><cfset ret = xlsTable.easy_getCell("A3").setValue("Plums")><cfset ret = xlsTable.easy_getCell("B3").setValue("6")><cfset ret = xlsTable.easy_getCell("C3").setValue("9")><!-- Add array formula --><cfset ret = xlsSheet.easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3")><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Array formulas.xlsx")>
.NET:# Create an instance of the class that exports Excel files
workbook = ExcelDocument()
# Add a sheet
workbook.easy_addWorksheet("Array formula");
xlsSheet = workbook.easy_getSheet("Array formula");
# Get the table of data for the sheet
xlsTable = xlsSheet.easy_getExcelTable();
# Add data in cells
xlsTable.easy_getCell("A1").setValue("Item");
xlsTable.easy_getCell("B1").setValue("Quantity (kg)");
xlsTable.easy_getCell("C1").setValue("Price ($)");
xlsTable.easy_getCell("D1").setValue("Total");
xlsTable.easy_getCell("A2").setValue("Apples");
xlsTable.easy_getCell("B2").setValue("2");
xlsTable.easy_getCell("C2").setValue("4");
xlsTable.easy_getCell("A3").setValue("Plums");
xlsTable.easy_getCell("B3").setValue("6");
xlsTable.easy_getCell("C3").setValue("9");
# Add array formula
xlsSheet.easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
Java:# Create an instance of the class that exports Excel files
workbook = gateway.jvm.ExcelDocument()
# Add a sheet
workbook.easy_addWorksheet("Array formula");
xlsSheet = workbook.easy_getSheet("Array formula");
# Get the table of data for the sheet
xlsTable = xlsSheet.easy_getExcelTable();
# Add data in cells
xlsTable.easy_getCell("A1").setValue("Item");
xlsTable.easy_getCell("B1").setValue("Quantity (kg)");
xlsTable.easy_getCell("C1").setValue("Price ($)");
xlsTable.easy_getCell("D1").setValue("Total");
xlsTable.easy_getCell("A2").setValue("Apples");
xlsTable.easy_getCell("B2").setValue("2");
xlsTable.easy_getCell("C2").setValue("4");
xlsTable.easy_getCell("A3").setValue("Plums");
xlsTable.easy_getCell("B3").setValue("6");
xlsTable.easy_getCell("C3").setValue("9");
# Add array formula
xlsSheet.easy_addArrayFormula("D2:D3", "=B2:B3*C2:C3");
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Array formulas.xlsx");
External references
EasyXLS supports to build formulas that contain references to cells from other workbooks. The external reference must be an element inside a formula and looks similar to "='C:\Sample\[Excel.xlsx]Sheet1'!$A$10".
If a workbook is loaded and the workbook contains references to external documents, the external workbooks can be found using ExcelDocument.getExternalLinks method.
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formulas.xlsx");
// Get the external references
ExternalLinks externalFiles = workbook.getExternalLinks();
for (int link=0; link < externalFiles.Count(); link++){
Console.WriteLine(externalFiles.getLinkAt(link));
}
' Create an instance of the class that imports Excel filesDim workbook As New ExcelDocument
' Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formulas.xlsx")
' Get the external referencesDim externalFiles = workbook.getExternalLinks()
For link As Integer = 0 To externalFiles.Count
Console.Write(externalFiles.getLinkAt(link))
Next
C++// Create an instance of the class that imports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Load Excel file
workbook->easy_LoadXLSXFile("C:\\Samples\\Formulas.xlsx");
// Get the external references
EasyXLS::IExternalLinksPtr externalFiles = workbook->getExternalLinks();
for (int link = 0; link < externalFiles->Count(); link++)
{
printf(externalFiles->getLinkAt(link));
}
C++.NET// Create an instance of the class that imports Excel files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Load Excel file
workbook->easy_LoadXLSXFile("C:\\Samples\\Formulas.xlsx");
// Get the external references
ExternalLinks ^externalFiles = workbook->getExternalLinks();
for (int link = 0; link < externalFiles->Count(); link++) {
Console::Write(externalFiles->getLinkAt(link));
}
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formulas.xlsx");
// Get the external references
ExternalLinks externalFiles = workbook.getExternalLinks();
for (int link=0; link < externalFiles.Count(); link++){
System.out.println(externalFiles.getLinkAt(link));
}
.NET:// Create an instance of the class that imports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Load Excel file
$workbook->easy_LoadXLSXFile("C:\Samples\Formulas.xlsx");
// Get the external references
$externalFiles = $workbook->getExternalLinks();
for ($link=0; $link < $externalFiles->count(); $link++){
echo $externalFiles->getLinkAt($link);
}
Java:// Create an instance of the class that imports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Load Excel file
$workbook->easy_LoadXLSXFile("C:\Samples\Formulas.xlsx");
// Get the external references
$externalFiles = $workbook->getExternalLinks();
for ($link=0; $link < (int)(string)$externalFiles->count(); $link++){
echo $externalFiles->getLinkAt($link);
}
' Create an instance of the class that imports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Formulas.xlsx")
' Get the external referencesset externalFiles = workbook.getExternalLinks()
for link=0 to externalFiles.Count()-1
response.write(externalFiles.getLinkAt(link))
next
' Create an instance of the class that imports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Formulas.xlsx")
' Get the external referencesSet externalFiles = workbook.getExternalLinks()
For link=0 To externalFiles.Count()-1
Me.Label1.Caption = Me.Label1.Caption & vbCrLf & externalFiles.getLinkAt(link)
Next
' Create an instance of the class that imports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load Excel file
workbook.easy_LoadXLSXFile("C:\Samples\Formulas.xlsx")
' Get the external referencesSet externalFiles = workbook.getExternalLinks()
For link=0 To externalFiles.Count()-1
response.write(externalFiles.getLinkAt(link))
Next
<!-- Create an instance of the class that imports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Load Excel file --><cfset ret = workbook.easy_LoadXLSXFile("C:\Samples\Formulas.xlsx")><!-- Get the external references --><cfset externalFiles = workbook.getExternalLinks()><cfloop from="0"to="#externalFiles.Count()#"index="link"><cfoutput>
#externalFiles.getLinkAt(link)#
</cfoutput>
</cfloop>
.NET:# Create an instance of the class that imports Excel files
workbook = ExcelDocument()
# Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formulas.xlsx")
# Get the external references
externalFiles = workbook.getExternalLinks()
for link in range(externalFiles.Count()):
print(externalFiles.getLinkAt(link))
Java:# Create an instance of the class that imports Excel files
workbook = gateway.jvm.ExcelDocument()
# Load Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\Formulas.xlsx")
# Get the external references
externalFiles = workbook.getExternalLinks()
for link in range(externalFiles.Count()):
print(externalFiles.getLinkAt(link))
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.