Ejemplo n.º 1
0
        /// <summary>
        /// 测试 Excel 保护.
        /// </summary>
        public void TestProtect()
        {
            Console.WriteLine("测试 Excel 保护开始!");

            string fileName =
                System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
                + @"ExcelFiles\测试工作表保护.xls";

            ExcelReport service = new ExcelReport();

            // 打开 Excel.
            service.OpenExcel();

            // 打开 Excel 文件.
            service.OpenExcelFile(fileName);

            // 允许用户编辑区域.
            service.AddProtectionAllowEditRanges(
                "测试工作表保护",
                "可编辑区域",
                "D5",
                "D8");

            // 保护.
            service.Protect("测试工作表保护");

            // 保存 Excel 文件.
            service.SaveExcelFile();

            // 关闭 Excel.
            service.CloseExcel();

            Console.WriteLine("测试 Excel 保护结束!");
        }