41
loading...
This website collects cookies to deliver better user experience
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/InputData.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the Excel document.
IWorkbook workbook = application.Workbooks.Open(input);
//Set Read only.
workbook.ReadOnlyRecommended = true;
FileStream output = new FileStream("../../../Output/ReadOnlyOutput.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the document.
workbook.SaveAs(output);
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/InputData.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the Excel document.
IWorkbook workbook = application.Workbooks.Open(input);
IWorksheet worksheet = workbook.Worksheets[0];
//Unlock cell.
worksheet["A1"].CellStyle.Locked = false;
FileStream output = new FileStream("../../../Output/LockedCells.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect");
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.LockedCells);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.UnLockedCells);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.FormattingCells);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.FormattingColumns);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.FormattingRows);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.InsertingColumns);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.InsertingRows);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.InsertingHyperlinks);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.DeletingColumns);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.DeletingRows);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.Sorting);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.Filtering);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.UsingPivotTables);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.Objects);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Protect("Protect", ExcelSheetProtection.Scenarios);
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/InputData.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the Excel document.
IWorkbook workbook = application.Workbooks.Open(input);
IWorksheet worksheet = workbook.Worksheets[0];
//Protect the worksheet with multiple options.
worksheet.Protect("Protect", ExcelSheetProtection.FormattingCells | ExcelSheetProtection.LockedCells |
ExcelSheetProtection.UnLockedCells);
FileStream output = new FileStream("../../../Output/ProtectedSheet.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/ProtectedWorksheet.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the Excel document.
IWorkbook workbook = application.Workbooks.Open(input);
IWorksheet worksheet = workbook.Worksheets[0];
//UnProtect the worksheet with password.
worksheet.Unprotect("syncfusion");
FileStream output = new FileStream("../../../Output/UnProtectedSheet.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/InputWorkbook.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the Excel document.
IWorkbook workbook = application.Workbooks.Open(input);
IWorksheet worksheet = workbook.Worksheets[0];
//Protect the workbook structure and windows with a password. Here, we have provided true for protecting structure and windows.
workbook.Protect(true, true, "syncfusion");
FileStream output = new FileStream("../../../Output/ProtectedWorkbook.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/InputWorkbook.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the Excel document.
IWorkbook workbook = application.Workbooks.Open(input);
IWorksheet worksheet = workbook.Worksheets[0];
//UnProtect the workbook with the password.
workbook.Unprotect("syncfusion");
FileStream output = new FileStream("../../../Output/UnProtectedWorkbook.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/InputExcel.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the Excel document.
IWorkbook workbook = application.Workbooks.Open(input);
IWorksheet worksheet = workbook.Worksheets[0];
//Encrypt the workbook with password.
workbook.PasswordToOpen = "syncfusion";
FileStream output = new FileStream("../../../Output/EncryptedWorkbook.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream input = new FileStream("../../../Data/EncryptedWorkbook.xlsx", FileMode.Open, FileAccess.ReadWrite);
//Open the encrypted Excel document with a password.
IWorkbook workbook = application.Workbooks.Open(input, ExcelParseOptions.Default, false, "syncfusion");
IWorksheet worksheet = workbook.Worksheets[0];
//Decrypt the workbook.
workbook.PasswordToOpen = string.Empty;
FileStream output = new FileStream("../../../Output/DecryptedWorkbook.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
FileStream input = new FileStream("../../../Data/InputData.xlsx", FileMode.Open, FileAccess.ReadWrite);
IWorkbook workbook = application.Workbooks.Open(input);
//Set workbook as final.
workbook.MarkAsFinal();
FileStream output = new FileStream("../../../Output/MarkAsFinalOutput.xlsx", FileMode.Create, FileAccess.ReadWrite);
//Save the modified document.
workbook.SaveAs(output);
}