Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,48 @@ static void Main(string[] args)
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];

//Applying conditional formatting to "A1"
IConditionalFormats condition = worksheet.Range["A1"].ConditionalFormats;
//Applying conditional formatting to "F2"
IConditionalFormats condition = worksheet.Range["F2"].ConditionalFormats;
IConditionalFormat condition1 = condition.AddCondition();

//Represents conditional format rule that the value in target range should be between 10 and 20
condition1.FormatType = ExcelCFType.CellValue;
condition1.Operator = ExcelComparisonOperator.Between;
condition1.FirstFormula = "10";
condition1.SecondFormula = "20";
worksheet.Range["A1"].Text = "Enter a number between 10 and 20";
worksheet.Range["A2"].Text = "Enter a number between 10 and 20";
worksheet.Range["F2"].BorderAround(ExcelLineStyle.Thin);

//Setting back color and font style to be applied for target range
condition1.BackColor = ExcelKnownColors.Light_orange;
condition1.IsBold = true;
condition1.IsItalic = true;

//Applying conditional formatting to "A3"
condition = worksheet.Range["A3"].ConditionalFormats;
//Applying conditional formatting to "F4"
condition = worksheet.Range["F4"].ConditionalFormats;
IConditionalFormat condition2 = condition.AddCondition();

//Represents conditional format rule that the cell value should be 1000
condition2.FormatType = ExcelCFType.CellValue;
condition2.Operator = ExcelComparisonOperator.Equal;
condition2.FirstFormula = "1000";
worksheet.Range["A3"].Text = "Enter the Number as 1000";
worksheet.Range["A4"].Text = "Enter the Number as 1000";
worksheet.Range["F4"].BorderAround(ExcelLineStyle.Thin);

//Setting fill pattern and back color to target range
condition2.FillPattern = ExcelPattern.LightUpwardDiagonal;
condition2.BackColor = ExcelKnownColors.Yellow;

//Applying conditional formatting to "A5"
condition = worksheet.Range["A5"].ConditionalFormats;
//Applying conditional formatting to "F6"
condition = worksheet.Range["F6"].ConditionalFormats;
IConditionalFormat condition3 = condition.AddCondition();

//Setting conditional format rule that the cell value for target range should be less than or equal to 1000
condition3.FormatType = ExcelCFType.CellValue;
condition3.Operator = ExcelComparisonOperator.LessOrEqual;
condition3.FirstFormula = "1000";
worksheet.Range["A5"].Text = "Enter a Number which is less than or equal to 1000";
worksheet.Range["A6"].Text = "Enter a Number which is less than or equal to 1000";
worksheet.Range["F6"].BorderAround(ExcelLineStyle.Thin);

//Setting back color to target range
condition3.BackColor = ExcelKnownColors.Light_green;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Main(string[] args)
workbook.SaveAsJson(outputStream);

//Saves the workbook to a JSON filestream as schema
FileStream stream1 = new FileStream("Output/Excel-Workbook-To-JSON-as-schema.json", FileMode.Create, FileAccess.ReadWrite);
FileStream stream1 = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema.json"), FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAsJson(stream1, true);
#endregion

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Protect a workbook with a password using C#

The Syncfusion® [.NET Excel Library](https://www.syncfusion.com/document-processing/excel-framework/net/excel-library) (XlsIO) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can **protect a workbook with a password** using C#.
The Syncfusion® [.NET Excel Library](https://www.syncfusion.com/document-processing/excel-framework/net/excel-library) (XlsIO) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can **protect a workbook with a password** using C#. After adding workbook protection, the structural changes of the workbook are disabled.

## Steps to protect a workbook with a password programmatically

Expand Down
Loading