EasyXLS™ library enables you to protect and lock Excel cells and Excel sheet objects (images, charts, comments, etc.) in order to prevent editing or deleting the sheet elements.
The component also allows setting a sheet password for worksheets and chart sheets when protecting the Excel sheet elements. The password is optional. If set, the user cannot edit the sheet elements until the valid password is supplied.
EasyXLS also permits to protect formulas and hide formulas expressions.
// Create an instance of the class that exports Excel file, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
// Protect Excel sheet
workbook.easy_getSheetAt(0).setSheetProtected(true);
// Get the table of data for the first worksheet that will keep the data
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
...
// Add data to cells for report valuesfor (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(row+1, column).setValue(
"Data " + (row + 1) + ", " + (column + 1));
}
}
// Create a formatting style for cells
ExcelStyle xlsStyleData = new ExcelStyle();
xlsStyleData.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT);
xlsStyleData.setForeground(Color.DarkGray);
xlsStyleData.setWrap(false);
xlsStyleData.setDataType(DataType.STRING);
// Apply locked cells property to the formatting style
xlsStyleData.setLocked(true);
xlsFirstTable.easy_setRangeStyle("A2:E101", xlsStyleData);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Protected Excel sheet.xlsx");
' Create an instance of the class that exports Excel file, having two sheetsDim workbook As New ExcelDocument(2)
' Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
' Protect Excel sheet
workbook.easy_getSheetAt(0).setSheetProtected(True)
' Get the table of data for the first worksheet that will keep the dataDim xlsFirstTab As ExcelWorksheet = workbook.easy_getSheetAt(0)
Dim xlsFirstTable = xlsFirstTab.easy_getExcelTable()
...
' Add data to cells for report valuesFor row As Integer = 0 To 99
For column As Integer = 0 To 4
xlsFirstTable.easy_getCell(row + 1, column).setValue( _
"Data " & (row + 1) & ", " & (column + 1))
NextNext' Create a formatting style for cellsDim xlsStyleData As New ExcelStyle
xlsStyleData.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT)
xlsStyleData.setForeground(Color.DarkGray)
xlsStyleData.setWrap(False)
xlsStyleData.setDataType(DataType.STRING)
' Apply locked cells property to the formatting style
xlsStyleData.setLocked(True)
xlsFirstTable.easy_setRangeStyle("A2:E101", xlsStyleData)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Protected Excel sheet.xlsx")
C++// Create an instance of the class that exports Excel file
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook);
// Create two sheets
workbook->easy_addWorksheet_2("First tab");
workbook->easy_addWorksheet_2("Second tab");
// Protect Excel sheet
workbook->easy_getSheetAt(0)->setSheetProtected(true);
// Get the table of data for the first worksheet that will keep the data
EasyXLS::IExcelWorksheetPtr xlsFirstTab =
(EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0);
EasyXLS::IExcelTablePtr xlsFirstTable = xlsFirstTab->easy_getExcelTable();
...
// Create a formatting style for cells
EasyXLS::IExcelStylePtr xlsStyleData;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelStyle),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelStyle),
(void**) &xlsStyleData) ;
xlsStyleData->setHorizontalAlignment(ALIGNMENT_ALIGNMENT_LEFT);
xlsStyleData->setForeground(COLOR_DARKGRAY);
xlsStyleData->setWrap(false);
// Apply locked cells property to the formatting style
xlsStyleData->setLocked(true);
xlsStyleData->setDataType(DATATYPE_STRING);
// Add data to cells for report valueschar* rowNumber = (char*)malloc(sizeof(char));
for (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
strcpy(cellValue, "Data ");
_itoa(column+ 1, columnNumber , 10);
_itoa(row + 1, rowNumber , 10);
strcat(cellValue, rowNumber);
strcat(cellValue, ", ");
strcat(cellValue, columnNumber);
xlsFirstTable->easy_getCell(row+1,column)->setValue(cellValue);
xlsFirstTable->easy_getCell(row+1,column)->setStyle(xlsStyleData);
}
}
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Protected Excel sheet.xlsx");
Click here to see Continuous Code ListingC++.NET// Create an instance of the class that exports Excel file, having two sheets
ExcelDocument ^workbook = gcnew ExcelDocument(2);
// Set the sheet names
workbook->easy_getSheetAt(0)->setSheetName("First tab");
workbook->easy_getSheetAt(1)->setSheetName("Second tab");
// Protect Excel sheet
workbook->easy_getSheetAt(0)->setSheetProtected(true);
// Get the table of data for the first worksheet that will keep the data
ExcelWorksheet ^xlsFirstTab =
safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0));
ExcelTable ^xlsFirstTable = xlsFirstTab->easy_getExcelTable();
...
// Add data to cells for report valuesfor (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
xlsFirstTable->easy_getCell(row+1,column)->setValue(String::Concat(
"Data ", (row + 1).ToString(), ", ", (column + 1).ToString()));
}
}
// Create a formatting style for cells
ExcelStyle ^xlsStyleData = gcnew ExcelStyle();
xlsStyleData->setHorizontalAlignment(Alignment::ALIGNMENT_LEFT);
xlsStyleData->setForeground(Color::DarkGray);
xlsStyleData->setWrap(false);
xlsStyleData->setDataType(DataType::STRING);
// Apply locked cells property to the formatting style
xlsStyleData->setLocked(true);
xlsFirstTable->easy_setRangeStyle("A2:E101", xlsStyleData);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Protected Excel sheet.xlsx");
Click here to see Continuous Code Listing
// Create an instance of the class that exports Excel file, having two sheets
ExcelDocument workbook = new ExcelDocument(2);
// Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab");
workbook.easy_getSheetAt(1).setSheetName("Second tab");
// Protect Excel sheet
workbook.easy_getSheetAt(0).setSheetProtected(true);
// Get the table of data for the first worksheet that will keep the data
ExcelTable xlsFirstTable =
((ExcelWorksheet)workbook.easy_getSheetAt(0)).easy_getExcelTable();
...
// Add data to cells for report valuesfor (int row=0; row<100; row++)
{
for (int column=0; column<5; column++)
{
xlsFirstTable.easy_getCell(row+1, column).setValue(
"Data " + (row + 1) + ", " + (column + 1));
}
}
// Create a formatting style for cells
ExcelStyle xlsStyleData = new ExcelStyle();
xlsStyleData.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT);
xlsStyleData.setForeground(Color.LIGHT_GRAY);
xlsStyleData.setWrap(false);
xlsStyleData.setDataType(DataType.STRING);
// Apply locked cells property to the formatting style
xlsStyleData.setLocked(true);
xlsFirstTable.easy_setRangeStyle("A2:E101", xlsStyleData);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Protected Excel sheet.xlsx");
.NET:// Create an instance of the class that exports Excel file
$workbook = new COM("EasyXLS.ExcelDocument");
// Create two sheets
$workbook->easy_addWorksheet_2("First tab");
$workbook->easy_addWorksheet_2("Second tab");
// Protect Excel sheet
$workbook->easy_getSheetAt(0)->setSheetProtected(true);
// Get the table of data for the first worksheet that will keep the data
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
...
// Create a formatting style for cells
$xlsStyleData = new COM("EasyXLS.ExcelStyle");
$xlsStyleData->setHorizontalAlignment($ALIGNMENT_ALIGNMENT_LEFT);
$xlsStyleData->setForeground((int)$COLOR_DARKGRAY);
$xlsStyleData->setWrap(false);
// Apply locked cells property to the formatting style
$xlsStyleData->setLocked(true);
$xlsStyleData->setDataType($DATATYPE_STRING);
// Add data to cells for report valuesfor ($row=0; $row<100; $row++)
{
for ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell($row+1,$column)->setValue(
"Data " . ($row + 1) . ", " . ($column + 1));
$xlsFirstTable->easy_getCell($row+1,$column)->setStyle($xlsStyleData);
}
}
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Protected Excel sheet.xlsx");
Click here to see Continuous Code ListingJava:// Create an instance of the class that creates Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Create two worksheets
$workbook->easy_addWorksheet("First tab");
$workbook->easy_addWorksheet("Second tab");
// Protect first sheet
$workbook->easy_getSheetAt(0)->setSheetProtected(true);
// Get the table of data for the first worksheet
$xlsFirstTable = $workbook->easy_getSheetAt(0)->easy_getExcelTable();
...
// Create a formatting style for cells
$xlsStyleData = new java("EasyXLS.ExcelStyle");
$xlsStyleData->setHorizontalAlignment($ALIGNMENT_ALIGNMENT_LEFT);
$xlsStyleData->setForeground(java("java.awt.Color")->LIGHT_GRAY);
$xlsStyleData->setWrap(false);
// Protect cells
$xlsStyleData->setLocked(true);
$xlsStyleData->setDataType($DATATYPE_STRING);
// Add data in cells for report valuesfor ($row=0; $row<100; $row++)
{
for ($column=0; $column<5; $column++)
{
$xlsFirstTable->easy_getCell($row+1,$column)->setValue("Data " . ($row + 1) .
", " . ($column + 1));
$xlsFirstTable->easy_getCell($row+1,$column)->setStyle($xlsStyleData);
}
}
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Protected Excel sheet.xlsx");
Click here to see Continuous Code Listing
' Create an instance of the class that exports Excel fileset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Protect Excel sheet
workbook.easy_getSheetAt(0).setSheetProtected(true)
' Get the table of data for the first worksheet that will keep the dataSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Create a formatting style for cellsSet xlsStyleData = Server.CreateObject("EasyXLS.ExcelStyle")
xlsStyleData.setHorizontalAlignment(ALIGNMENT_ALIGNMENT_LEFT)
xlsStyleData.setForeground(CLng(COLOR_DARKGRAY))
xlsStyleData.setWrap(False)
' Apply locked cells property to the formatting style
xlsStyleData.setLocked(True)
xlsStyleData.setDataType(DATATYPE_STRING)
' Add data to cells for report valuesfor row = 0 to 99
for column = 0 to 4
xlsFirstTable.easy_getCell(row+1,column).setValue( _
"Data " & (row + 1) & ", " & (column + 1))
xlsFirstTable.easy_getCell(row+1,column).setStyle(xlsStyleData)
nextnext' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Protected Excel sheet.xlsx")
' Create an instance of the class that exports Excel fileSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2 ("First tab")
workbook.easy_addWorksheet_2 ("Second tab")
' Protect Excel sheet
workbook.easy_getSheetAt(0).setSheetProtected (True)
' Get the table of data for the first worksheet that will keep the dataSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Create a formatting style for cellsSet xlsStyleData = CreateObject("EasyXLS.ExcelStyle")
xlsStyleData.setHorizontalAlignment (Alignment.ALIGNMENT_ALIGNMENT_LEFT)
xlsStyleData.setForeground (CLng(Color.COLOR_DARKGRAY))
xlsStyleData.setWrap (False)
' Apply locked cells property to the formatting style
xlsStyleData.setLocked (True)
xlsStyleData.setDataType (DataType.DATATYPE_STRING)
' Add data to cells for report valuesFor row = 0 To 99
For Column = 0 To 4
xlsFirstTable.easy_getCell(row + 1, Column).setValue ( _
"Data " & (row + 1) & ", " & (Column + 1))
xlsFirstTable.easy_getCell(row + 1, Column).setStyle (xlsStyleData)
NextNext' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Protected Excel sheet.xlsx")
' Create an instance of the class that exports Excel fileSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Create two sheets
workbook.easy_addWorksheet_2("First tab")
workbook.easy_addWorksheet_2("Second tab")
' Protect Excel sheet
workbook.easy_getSheetAt(0).setSheetProtected(true)
' Get the table of data for the first worksheet that will keep the dataSet xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
' Create a formatting style for cellsSet xlsStyleData = CreateObject("EasyXLS.ExcelStyle")
xlsStyleData.setHorizontalAlignment(ALIGNMENT_LEFT)
xlsStyleData.setForeground(CLng(DARKGRAY))
xlsStyleData.setWrap(False)
' Apply locked cells property to the formatting style
xlsStyleData.setLocked(True)
xlsStyleData.setDataType(DATATYPE_STRING)
' Add data to cells for report valuesfor row = 0 to 99
for column = 0 to 4
xlsFirstTable.easy_getCell(row+1,column).setValue( _
"Data " & (row + 1) & ", " & (column + 1))
xlsFirstTable.easy_getCell(row+1,column).setStyle(xlsStyleData)
nextnext' Export Excel file
workbook.easy_WriteXLSXFile ("C:\Samples\Protected Excel sheet.xlsx")
<!-- Create an instance of the class that exports Excel file --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Create two sheets --><cfset ret = workbook.easy_addWorksheet("First tab")><cfset ret = workbook.easy_addWorksheet("Second tab")><!-- Protect Excel sheet --><cfset workbook.easy_getSheetAt(0).setSheetProtected(true)><!-- Get the table of data for the first worksheet that will keep the data --><cfset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()>
...
<!-- Create a formatting style for cells --><cfobject type="java"class="EasyXLS.ExcelStyle"name="xlsStyleData"action="CREATE"><cfset xlsStyleData.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT)><cfset xlsStyleData.setForeground(Color.lightGray)><cfset xlsStyleData.setWrap(false)><!--Apply locked cells property to the formatting style --><cfset xlsStyleData.setLocked(true)><cfset xlsStyleData.setDataType(DataType.STRING)><!-- Add data to cells for report values --><cfloop from="0"to="99"index="row"><cfloop from="0"to="4"index="column"><cfset xlsFirstTable.easy_getCell(evaluate(row + 1),evaluate(column)).setValue(
"Data " & evaluate(row + 1) & ", " & evaluate(column + 1))><cfset xlsFirstTable.easy_getCell(evaluate(row + 1),evaluate(column)).setStyle(
xlsStyleData)>
</cfloop>
</cfloop><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Protected Excel sheet.xlsx")>
.NET:# Create an instance of the class that creates Excel files, having two sheets
workbook = ExcelDocument(2)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
# Protect first sheet
workbook.easy_getSheetAt(0).setSheetProtected(True)
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
# Add data in cells for report valuesfor row in range(100):
for column in range(5):
xlsFirstTable.easy_getCell(row+1, column).setValue("Data " + str(row + 1) + ", " + str(column + 1))
# Create a formatting style for cells
xlsStyleData = ExcelStyle()
xlsStyleData.setHorizontalAlignment(Alignment.ALIGNMENT_LEFT)
xlsStyleData.setForeground(Color.DarkGray)
xlsStyleData.setWrap(False)
xlsStyleData.setDataType(DataType.STRING)
xlsStyleData.setLocked(True)
xlsFirstTable.easy_setRangeStyle("A2:E101", xlsStyleData)
# Create Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Protected Excel sheet.xlsx")
Click here to see Continuous Code ListingJava:# Create an instance of the class that creates Excel files, having two sheets
workbook = gateway.jvm.ExcelDocument(2)
# Set the sheet names
workbook.easy_getSheetAt(0).setSheetName("First tab")
workbook.easy_getSheetAt(1).setSheetName("Second tab")
# Protect first sheet
workbook.easy_getSheetAt(0).setSheetProtected(True)
# Get the table of data for the first worksheet
xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()
...
# Add data in cells for report valuesfor row in range(100):
for column in range(5):
xlsFirstTable.easy_getCell(row+1, column).setValue("Data " + str(row + 1) + ", " + str(column + 1))
# Create a formatting style for cells
xlsStyleData = gateway.jvm.ExcelStyle()
xlsStyleData.setHorizontalAlignment(gateway.jvm.Alignment.ALIGNMENT_LEFT)
xlsStyleData.setForeground(gateway.jvm.Color.LIGHT_GRAY)
xlsStyleData.setWrap(False)
xlsStyleData.setDataType(gateway.jvm.DataType.STRING)
xlsStyleData.setLocked(True)
xlsFirstTable.easy_setRangeStyle("A2:E101", xlsStyleData)
# Create Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Protected Excel sheet.xlsx")
Click here to see Continuous Code Listing
The screen shot provides an example of an exported Excel file that has the sheet protected.
// 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)");
xlsTable.easy_getCell("A6").setHiddenFormula(true);
// Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected(true);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Hidden formula.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)")
xlsTable.easy_getCell("A6").setHiddenFormula(True)
' Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected(True)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Hidden formula.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)");
xlsTable->easy_getCell_2("A6")->setHiddenFormula(true);
// Protect Excel sheet
workbook->easy_getSheet("Formula")->setSheetProtected(true);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Hidden formula.xlsx");
C++.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)");
xlsTable->easy_getCell("A6")->setHiddenFormula(true);
// Protect Excel sheet
workbook->easy_getSheet("Formula")->setSheetProtected(true);
// Export Excel file
workbook->easy_WriteXLSXFile("C:\\Samples\\Hidden formula.xlsx");
// 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)");
xlsTable.easy_getCell("A6").setHiddenFormula(true);
// Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected(true);
// Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Hidden formula.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)");
$xlsTable->easy_getCell_2("A6")->setHiddenFormula(true);
// Protect Excel sheet
$workbook->easy_getSheet("Formula")->setSheetProtected(true);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Hidden formula.xlsx");
Java:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Add a sheet
$workbook->easy_addWorksheet("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("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)");
$xlsTable->easy_getCell("A6")->setHiddenFormula(true);
// Protect Excel sheet
$workbook->easy_getSheet("Formula")->setSheetProtected(true);
// Export Excel file
$workbook->easy_WriteXLSXFile("C:\Samples\Hidden formula.xlsx");
' 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)")
xlsTable.easy_getCell_2("A6").setHiddenFormula(true)
' Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected(true)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Hidden formula.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)")
xlsTable.easy_getCell_2("A6").setHiddenFormula (True)
' Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected (True)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Hidden formula.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)")
xlsTable.easy_getCell_2("A6").setHiddenFormula(True)
' Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected(True)
' Export Excel file
workbook.easy_WriteXLSXFile("C:\Samples\Hidden formula.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 ret = xlsTable.easy_getCell("A1").setValue("1")><cfset ret = xlsTable.easy_getCell("A2").setValue("2")><cfset ret = xlsTable.easy_getCell("A3").setValue("3")><cfset ret = xlsTable.easy_getCell("A4").setValue("4")><cfset ret = xlsTable.easy_getCell("A6").setValue("=SUM(A1:A4)")><cfset ret = xlsTable.easy_getCell("A6").setHiddenFormula(true)><!-- Protect Excel sheet --><cfset ret = workbook.easy_getSheet("Formula").setSheetProtected(true)><!-- Export Excel file --><cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Hidden formula.xlsx")>
.NET:# Create an instance of the class that exports Excel files
workbook = ExcelDocument()
# Add a sheet
workbook.easy_addWorksheet("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("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)")
xlsTable.easy_getCell("A6").setHiddenFormula(True)
# Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected(True)
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Hidden formula.xlsx")
Java:# Create an instance of the class that exports Excel files
workbook = gateway.jvm.ExcelDocument()
# Add a sheet
workbook.easy_addWorksheet("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("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)")
xlsTable.easy_getCell("A6").setHiddenFormula(True)
# Protect Excel sheet
workbook.easy_getSheet("Formula").setSheetProtected(True)
# Export Excel file
workbook.easy_WriteXLSXFile("C:\\Samples\\Hidden formula.xlsx")
EasyXLS automatically protects the Excel sheet objects like images, charts, comments and other objects when the sheet is protected using ExcelSheet.setSheetProtected method.