当前位置: 首页>>代码示例>>C#>>正文


C# Application.Run方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Excel.Application.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Application.Run方法的具体用法?C# Application.Run怎么用?C# Application.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Excel.Application的用法示例。


在下文中一共展示了Application.Run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: insertmacro


//.........这里部分代码省略.........
              "End Function\r\n" +
              " \r\n" +
              "Private Function TryWorkbookPasswordSize( _\r\n" +
              "      ByVal Size As Long, _\r\n" +
              "      ByRef PasswordsTried As Long, _\r\n" +
              "      ByRef Password As String, _\r\n" +
              "      Optional ByVal Base As String _\r\n" +
              "   ) As Boolean\r\n" +
              "  \r\n" +
              "   Dim Index As Long\r\n" +
              "  \r\n" +
              "   On Error Resume Next\r\n" +
              "   If IsMissing(Base) Then Base = vbNullString\r\n" +
              "   If Len(Base) < Size - 1 Then\r\n" +
              "      For Index = 65 To 66\r\n" +
              "         If TryWorkbookPasswordSize(Size, PasswordsTried, Password, Base & Chr(Index)) Then\r\n" +
              "            TryWorkbookPasswordSize = True\r\n" +
              "            Exit Function\r\n" +
              "         End If\r\n" +
              "      Next Index\r\n" +
              "   ElseIf Len(Base) < Size Then\r\n" +
              "      For Index = 32 To 255\r\n" +
              "         ActiveWorkbook.Unprotect Base & Chr(Index)\r\n" +
              "         If Not ActiveWorkbook.ProtectStructure And Not ActiveWorkbook.ProtectWindows Then\r\n" +
              "            TryWorkbookPasswordSize = True\r\n" +
              "            Password = Base & Chr(Index)\r\n" +
              "            Exit Function\r\n" +
              "         End If\r\n" +
              "         PasswordsTried = PasswordsTried + 1\r\n" +
              "      Next Index\r\n" +
              "   End If\r\n" +
              "   On Error GoTo 0\r\n" +
              "  \r\n" +
              "   DisplayStatus PasswordsTried\r\n" +
              " \r\n" +
              "End Function\r\n" +
              " \r\n" +
              "Public Sub UnlockSheet()\r\n" +
              " \r\n" +
              "   Dim PasswordSize As Variant\r\n" +
              "   Dim PasswordsTried As Long\r\n" +
              "   Dim Password As String\r\n" +
              " \r\n" +
              "   PasswordsTried = 0\r\n" +
              "   If Not ActiveSheet.ProtectContents Then\r\n" +
              "      Exit Sub\r\n" +
              "   End If\r\n" +
              "   On Error Resume Next\r\n" +
              "   ActiveSheet.Protect \"\"\r\n" +
              "   ActiveSheet.Unprotect \"\"\r\n" +
              "   On Error GoTo 0\r\n" +
              "   If ActiveSheet.ProtectContents Then\r\n" +
              "      For Each PasswordSize In Array(5, 4, 6, 7, 8, 3, 2, 1)\r\n" +
              "         If TrySheetPasswordSize(PasswordSize, PasswordsTried, Password) Then Exit For\r\n" +
              "      Next PasswordSize\r\n" +
              "   End If\r\n" +
              "   If Not ActiveSheet.ProtectContents Then\r\n" +
              "   End If\r\n" +
              "   Application.StatusBar = False\r\n" +
              "  \r\n" +
              "End Sub\r\n" +
              " \r\n" +
              "Public Sub UnlockWorkbook()\r\n" +
              " \r\n" +
              "   Dim PasswordSize As Variant\r\n" +
              "   Dim PasswordsTried As Long\r\n" +
              "   Dim Password As String\r\n" +
              "  \r\n" +
              "   PasswordsTried = 0\r\n" +
              "   If Not ActiveWorkbook.ProtectStructure And Not ActiveWorkbook.ProtectWindows Then\r\n" +
              "      Exit Sub\r\n" +
              "   End If\r\n" +
              "   On Error Resume Next\r\n" +
              "   ActiveWorkbook.Unprotect vbNullString\r\n" +
              "   On Error GoTo 0\r\n" +
              "   If ActiveWorkbook.ProtectStructure Or ActiveWorkbook.ProtectWindows Then\r\n" +
              "      For Each PasswordSize In Array(5, 4, 6, 7, 8, 3, 2, 1)\r\n" +
              "         If TryWorkbookPasswordSize(PasswordSize, PasswordsTried, Password) Then Exit For\r\n" +
              "      Next PasswordSize\r\n" +
              "   End If\r\n" +
              "   If Not ActiveWorkbook.ProtectStructure And Not ActiveWorkbook.ProtectWindows Then\r\n" +
              "   End If\r\n" +
              "   Application.StatusBar = False\r\n" +
              "  \r\n" +
              "End Sub";
            Console.WriteLine("A injectar o codigo...");
            oModule.CodeModule.AddFromString(sCode);

            Console.WriteLine("A tentar desbloquear o livro todo...");
            oExcel.Run("UnlockWorkbook");
            Console.WriteLine("A tentar desbloquear as sheets...");
            oExcel.Run("UnlockSheet");
            Console.WriteLine("Feito ;)");
            //System.IO.File.WriteAllText(@"c:\script.txt", sCode);
            oExcel.Visible = true;
            oModule = null;
            oBook = null;
            oExcel = null;
            GC.Collect();
        }
开发者ID:GRB,项目名称:ExcelUnlocker,代码行数:101,代码来源:Program.cs

示例2: btExcel_Click

 private void btExcel_Click(object sender, EventArgs e)
 {
     Excel.Application excelApp = new Excel.Application();
     excelApp.Visible = true;
     excelApp.Workbooks.Open(@"C:\University\patternExcel1.xltm");
     DataTable exTable = exampleDataTable();
     foreach (DataRow row in exTable.Rows)
     {
         excelApp.Run("ShowMsg", row["Singer"], row["Track"], row["ReleaseTrack"], row["Label"]);
     }
 }
开发者ID:DashaSerdyuk,项目名称:main,代码行数:11,代码来源:Form1.cs

示例3: Main


//.........这里部分代码省略.........
                            outCellB = ExcelCellRef(cellArr[1]);
                            iarg++;
                        }
                    }
                    else if (iarg == 5)
                    {
                        outCellB = ExcelCellRef(args[i]);
                    }

                    // output charts
                    else if (iarg > 5)
                    {
                        charts.Add(args[i]);
                    }

                    iarg++;
                }
            }

            // Print header
            if (showMan)
            {
                Print(@"Usage: excel [OPTIONS] ExcelFile PasteFile Cell1 Cell2 OutCell1 OutCell2 [Chart1 [Chart2 ..]]
               or: excel =FORMULA

            Opens ExcelFile and places the contents of PasteFile from position given.
            Position is the range between Cell1 and Cell2. Unused cells are cleared.
            Echos all filled rows in the range between OutCell1 and OutCell2.
            Any charts named will be saved to <ExcelFile_ChartN>.png.
            'Sheet.ChartN' can be used if multiple charts has the same name.

            -p PasteSheet   Select the sheet that should be pasted to.
            -s OutSheet     Select the sheet that should be outputted.
            -m Macro        Run macro after paste. If -m is used multiples
                    times, more than 1 macro can be executed.
            -n              Do not save workbook
            -w              display Excel dialogs. Default is to surpress.
            -#              Replace errors with blanks in output
            -b [CHAR]       Set cell-spacing character in output to
                    'space' or 'CHAR' (default is 'tab')
            -t              Insert PasteFile as text instead of numbers

            If '~' is specified as PasteFile no file is loaded and Cell1 and Cell2
            should not be specified.

            Version 1.0. Report bugs to <[email protected]>");
                Environment.Exit(0);
            }

            if (infile.StartsWith("="))
            {
                string result = "";
                try
                {
                    result = ExcelMath.Calc(infile);
                }
                catch (Exception ex) {

                    Console.Error.WriteLine("Error: " + ex.Message);
            #if DEBUG
                    Console.ReadKey();
            #endif
                    Environment.Exit(1);
                }

                Print(result);
开发者ID:martsve,项目名称:excel,代码行数:67,代码来源:main.cs


注:本文中的Microsoft.Office.Interop.Excel.Application.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。