Exemplo n.º 1
0
 /// <summary>
 /// Schreibt einen Wert in die Zelle des gegebenen Excel-Sheets
 /// </summary>
 /// <param name="sheet">Das Excel Sheet.</param>
 /// <param name="zelle">Die Zelle, z. B. A2.</param>
 /// <param name="value">Den Wert der Zelle als String.</param>
 public void WriteValueProtectedCell(Excel.Worksheet sheet, string zelle, string value)
 {
     sheet.Unprotect("1111");
       Excel.Range r = sheet.get_Range(zelle, missing);
       r.Value2 = value;
       sheet.Protect("1111", false, true);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 去保护工作表
 /// </summary>
 private void unLockExcel(Excel.Workbook wb, Excel.Worksheet xx)
 {
     try
     {
       
         
         xx.Unprotect("MyPassword");
         xx.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection;
         wb.SheetBeforeDoubleClick -= new Microsoft.Office.Interop.Excel.WorkbookEvents_SheetBeforeDoubleClickEventHandler(wb_SheetBeforeDoubleClick);  
     }
     catch { }
 }
Exemplo n.º 3
0
        private static void unLockExcel(Excel.Workbook wb, Excel.Worksheet xx)
        {
            try
            {


                xx.Unprotect("MyPassword");
                xx.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection;
              
            }
            catch { }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 去保护工作表
        /// </summary>
        public static void unLockExcel(Excel.Workbook wb, Excel.Worksheet xx)
        {
            try
            {


                xx.Unprotect("MyPassword");
                //xx.EnableSelection = Microsoft.Office.Interop.Excel.XlEnableSelection.xlNoSelection;
                //wb.SheetSelectionChange -= new Microsoft.Office.Interop.Excel.WorkbookEvents_SheetSelectionChangeEventHandler(Workbook_SheetSelectionChange);
                //wb.SheetBeforeDoubleClick -= new Microsoft.Office.Interop.Excel.WorkbookEvents_SheetBeforeDoubleClickEventHandler(wb_SheetBeforeDoubleClick);
            }
            catch { }
        }
Exemplo n.º 5
0
        private Excel.Workbook UnprotectWorkbookStructure(Excel.Workbook workbook)
        {
            string workbookStructurePassword = string.Empty;

            int attemptCount = 0;

            // This code is based on a routine found here (public university, University of Wisconsin, Green Bay): https://uknowit.uwgb.edu/page.php?id=28850

            for (int i = 65; i < 67; i++)
                for (int j = 65; j < 67; j++)
                    for (int k = 65; k < 67; k++)
                        for (int l = 65; l < 67; l++)
                            for (int m = 65; m < 67; m++)
                                for (int i1 = 65; i1 < 67; i1++)
                                    for (int i2 = 65; i2 < 67; i2++)
                                        for (int i3 = 65; i3 < 67; i3++)
                                            for (int i4 = 65; i4 < 67; i4++)
                                                for (int i5 = 65; i5 < 67; i5++)
                                                    for (int i6 = 65; i6 < 67; i6++)
                                                        for (int n = 32; n < 126; n++)
                                                        {
                                                            workbookStructurePassword = Convert.ToChar(i).ToString() + Convert.ToChar(j).ToString() + Convert.ToChar(k).ToString() + Convert.ToChar(l).ToString() + Convert.ToChar(m).ToString() +
                                                                Convert.ToChar(i1).ToString() + Convert.ToChar(i2).ToString() + Convert.ToChar(i3).ToString() + Convert.ToChar(i4).ToString() + Convert.ToChar(i5).ToString() +
                                                                Convert.ToChar(i6).ToString() + Convert.ToChar(n).ToString();

                                                            attemptCount++;

                                                            try
                                                            {
                                                                workbook.Unprotect(workbookStructurePassword);
                                                            }
                                                            catch { }

                                                            if (!workbook.ProtectStructure)
                                                            {
                                                                return workbook;
                                                            }
                                                        }

            return null;
        }
Exemplo n.º 6
0
        private Excel.Worksheet UnprotectSheet(Excel.Worksheet sheet)
        {
            if (!string.IsNullOrEmpty(_worksheetPassword))
            {
                try
                {
                    sheet.Unprotect(_worksheetPassword);
                }
                catch
                {

                }

                if (!sheet.ProtectContents)
                {
                    return sheet;
                }
            }

            // This code is based on a routine found here (public university, University of Wisconsin, Green Bay): https://uknowit.uwgb.edu/page.php?id=28850

            int attemptCount = 0;

            for (int i = 65; i < 67; i++)
                for (int j = 65; j < 67; j++)
                    for (int k = 65; k < 67; k++)
                        for (int l = 65; l < 67; l++)
                            for (int m = 65; m < 67; m++)
                                for (int i1 = 65; i1 < 67; i1++)
                                    for (int i2 = 65; i2 < 67; i2++)
                                        for (int i3 = 65; i3 < 67; i3++)
                                            for (int i4 = 65; i4 < 67; i4++)
                                                for (int i5 = 65; i5 < 67; i5++)
                                                    for (int i6 = 65; i6 < 67; i6++)
                                                        for (int n = 32; n < 126; n++)
                                                        {
                                                            _worksheetPassword = Convert.ToChar(i).ToString() + Convert.ToChar(j).ToString() + Convert.ToChar(k).ToString() + Convert.ToChar(l).ToString() + Convert.ToChar(m).ToString() +
                                                                Convert.ToChar(i1).ToString() + Convert.ToChar(i2).ToString() + Convert.ToChar(i3).ToString() + Convert.ToChar(i4).ToString() + Convert.ToChar(i5).ToString() +
                                                                Convert.ToChar(i6).ToString() + Convert.ToChar(n).ToString();

                                                            attemptCount++;

                                                            try
                                                            {
                                                                sheet.Unprotect(_worksheetPassword);
                                                            }
                                                            catch { }

                                                            if (!sheet.ProtectContents)
                                                            {
                                                                return sheet;
                                                            }
                                                        }

            return null;
        }