SpreadsheetLocker.Process

Process(string, string, string, string)

Locks spreadsheet file with specified settings.

public static void Process(string templateFile, string resultFile, string openPassword, 
    string writePassword)
ParameterTypeDescription
templateFileStringThe template file to be locked
resultFileStringThe resultant file
openPasswordStringPassword for file encryption
writePasswordStringPassword for protection of modifying spreadsheet

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.LowCode;
    using System;
    using System.IO;

    public class SpreadsheetLockerMethodProcessWithStringStringStringStringDemo
    {
        public static void Run()
        {           
            string templatePath = "template.xlsx";            
            // Prepare result file path
            string resultPath = "secured_spreadsheet.xlsx";

            try
            {
                // Execute Process method with string parameters directly using the type
                SpreadsheetLocker.Process(
                    templateFile: templatePath,
                    resultFile: resultPath,
                    openPassword: "Open@123",
                    writePassword: "Write@456"
                );

                Console.WriteLine($"Spreadsheet secured successfully. Saved to: {Path.GetFullPath(resultPath)}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error securing spreadsheet: {ex.Message}");
            }
            finally
            {
                // Clean up temporary template
                if (File.Exists(templatePath))
                {
                    File.Delete(templatePath);
                }
            }
        }
    }
}

See Also


Process(LowCodeLoadOptions, LowCodeSaveOptions, string, string)

Locks spreadsheet file with specified settings.

public static void Process(LowCodeLoadOptions loadOptions, LowCodeSaveOptions saveOptions, 
    string openPassword, string writePassword)
ParameterTypeDescription
loadOptionsLowCodeLoadOptionsOptions for input and loading
saveOptionsLowCodeSaveOptionsOptions for output and saving
openPasswordStringPassword for file encryption
writePasswordStringPassword for protection of modifying spreadsheet

Examples

using System;
using System.IO;
using Aspose.Cells.LowCode;

namespace AsposeCellsExamples
{
    public class SpreadsheetLockerMethodProcessWithLowCodeLoadOptionsLowCodeSaveODemo
    {
        public static void Run()
        {
            
            // Process the spreadsheet with lock/unlock passwords
            SpreadsheetLocker.Process(
                new LowCodeLoadOptions() { InputFile = "input.xlsx" },
                new LowCodeSaveOptions() 
                { 
                    OutputFile = "output_locked.xlsx" 
                }, 
                "123456", 
                "234567");
        }
    }
}

See Also


Process(LowCodeLoadOptions, LowCodeSaveOptions, string, string, string, ProtectionType)

Locks spreadsheet file with specified settings.

public static void Process(LowCodeLoadOptions loadOptions, LowCodeSaveOptions saveOptions, 
    string openPassword, string writePassword, string workbookPassword, ProtectionType workbookType)
ParameterTypeDescription
loadOptionsLowCodeLoadOptionsOptions for input and loading
saveOptionsLowCodeSaveOptionsOptions for output and saving
openPasswordStringPassword for file encryption
writePasswordStringPassword for protection of modifying spreadsheet
workbookPasswordStringPassword for protection of the workbook
workbookTypeProtectionTypeProtection type to protect the workbook

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.LowCode;
    using System;

    public class SpreadsheetLockerMethodProcessWithLowCodeLoadOptionsLowCodeSaveODemo2
    {
        public static void Run()
        {
            // Create LowCodeLoadOptions and LowCodeSaveOptions instances
            LowCodeLoadOptions loadOptions = new LowCodeLoadOptions();
            loadOptions.InputFile = "input.xlsx";
            LowCodeSaveOptions saveOptions = new LowCodeSaveOptions();
            saveOptions.OutputFile = "output.xlsx";

            // Define protection parameters
            string openPassword = "userOpen123";
            string writePassword = "userWrite123";
            string workbookPassword = "workbookProtect123";
            ProtectionType protectionType = ProtectionType.All;

            try
            {
                // Call the Process method directly without instantiating SpreadsheetLocker
                SpreadsheetLocker.Process(loadOptions, saveOptions, openPassword, writePassword, workbookPassword, protectionType);
                
                Console.WriteLine("Spreadsheet processed successfully with document protection settings.");
            }
            catch (CellsException ex)
            {
                Console.WriteLine($"Aspose.Cells error during processing: {ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"General error: {ex.Message}");
            }
        }
    }
}

See Also


Process(LowCodeLoadOptions, LowCodeSaveOptions, AbstractLowCodeProtectionProvider)

Locks spreadsheet file with specified settings.

public static void Process(LowCodeLoadOptions loadOptions, LowCodeSaveOptions saveOptions, 
    AbstractLowCodeProtectionProvider provider)
ParameterTypeDescription
loadOptionsLowCodeLoadOptionsOptions for input and loading
saveOptionsLowCodeSaveOptionsOptions for output and saving
providerAbstractLowCodeProtectionProviderImplementation to provide protections settings

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.LowCode;
    using System;

    public class SpreadsheetLockerMethodProcessWithLowCodeLoadOptionsLowCodeSaveODemo1
    {
        public static void Run()
        {
           
            // Prepare LowCodeLoadOptions
            LowCodeLoadOptions loadOptions = new LowCodeLoadOptions();
            loadOptions.InputFile = "input.xlsx";

            // Prepare LowCodeSaveOptions
            LowCodeSaveOptions saveOptions = new LowCodeSaveOptions();
            saveOptions.SaveFormat = SaveFormat.Xlsx;
            saveOptions.OutputFile = "output.xlsx";

            // Create a custom protection provider
            CustomProtectionProvider provider = new CustomProtectionProvider();

            try
            {
                // Call the static Process method with specified parameters
                SpreadsheetLocker.Process(loadOptions, saveOptions, provider);

                Console.WriteLine("Spreadsheet processed and protected successfully.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error processing spreadsheet: {ex.Message}");
            }

        }

        private class CustomProtectionProvider : AbstractLowCodeProtectionProvider
        {
            public override string GetOpenPassword()
            {
                return "open123";
            }

            public override string GetWritePassword()
            {
                return "write123";
            }

            public override string GetWorkbookPassword()
            {
                return "workbook123";
            }

            public override ProtectionType GetWorkbookProtectionType()
            {
                return ProtectionType.All;
            }
        }
    }
}

See Also