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


C# Interop.Excel类代码示例

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


Microsoft.Office.Interop.Excel类属于命名空间,在下文中一共展示了Microsoft.Office.Interop.Excel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Dispose

        /// <summary>
        /// 释放内存
        /// </summary>
        public void Dispose(Excel._Worksheet CurSheet, Excel._Workbook CurBook, Excel._Application CurExcel)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(CurSheet);
                CurSheet = null;
                CurBook.Close(false, mValue, mValue);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(CurBook);
                CurBook = null;

                CurExcel.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(CurExcel);
                CurExcel = null;

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (System.Exception)
            {
                // Response.Write("在释放Excel内存空间时发生了一个错误:" + ex);
            }
            finally
            {
                foreach (System.Diagnostics.Process pro in System.Diagnostics.Process.GetProcessesByName("Excel"))
                    //if (pro.StartTime < DateTime.Now)
                    pro.Kill();
            }
            System.GC.SuppressFinalize(this);
        }
开发者ID:refinedKing,项目名称:WeiXin--Vs2010-,代码行数:32,代码来源:ExcelOperate.cs

示例2: MakeBoldText

 private void MakeBoldText(Excel.Worksheet sheet, int firstCell, int lastCell, int row)
 {
     for (int i = firstCell; i < lastCell; i++)
     {
         mySheet.Cells[row, i].Font.Bold = true;
     }
 }
开发者ID:MalakhovVladislav,项目名称:practice,代码行数:7,代码来源:Exporter.cs

示例3: CloseExcel

 // closes Excel
 public static void CloseExcel(Excel.Application xlApp, Excel.Workbook wb)
 {
     // Close Excel
     object misValue = System.Reflection.Missing.Value;
     wb.Close(false, misValue, misValue);
     xlApp.Quit();
 }
开发者ID:jcollins1007,项目名称:xlScraper,代码行数:8,代码来源:xlScraper.cs

示例4: StudentWorkbook

    /// <summary>
    /// Class constructor does all the work
    /// </summary>
    /// <param name="excelApp"></param>
    /// <param name="fileName"></param>
    public StudentWorkbook( Excel.Application excelApp, string fileName )
    {
      try  // to open the student's spreadsheet
      {
        excelWorkbook = excelApp.Workbooks.Open( fileName, 0,
            true, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,  // read only
            false, 0, true, false, false );
      }
      catch ( Exception e )
      {
        Console.WriteLine( "error: " + e.Message );
        Console.WriteLine( "Could not open spreadsheet " + fileName );
      }

      Excel.Sheets excelSheets = excelWorkbook.Worksheets;  // get the Worksheets collection
      Excel.Worksheet excelWorksheet = excelSheets[ 1 ];    // get the first one

      // get the Team Number cell
      Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range( "B4", "B4" );

      // try to convert this cell to an integer
      if ( ( teamNumber = TryForInt( excelCell.Value ) ) == 0 )
      {
        Console.WriteLine( "\nTeam number invalid in " + fileName + "\n" );
      }

      // get the scores cells
      scores = excelWorksheet.get_Range( "B7", "B15" );

      // get the Additional Comments cell
      comments = excelWorksheet.get_Range( "B18", "B18" );

    }  // end of StudentWorkbook()
开发者ID:cyboss77,项目名称:ClassAssessments,代码行数:38,代码来源:StudentWorkbook.cs

示例5: CreateSalesPivotTable

        internal Excel.PivotTable CreateSalesPivotTable(Excel.Range range, String filePath)
        {
            string fileDirectory = System.IO.Path.GetDirectoryName(filePath);
            string fileName = System.IO.Path.GetFileName(filePath);

            string pivotTableName = Properties.Resources.SalesAndProfitPivotTableName;
            Excel.PivotCache cache = this.PivotCaches().Add(Excel.XlPivotTableSourceType.xlExternal, missing);

            cache.Connection = String.Format(
                CultureInfo.CurrentUICulture,
                salesPivotTableConnectionTemplate,
                fileDirectory);
            cache.CommandType = Excel.XlCmdType.xlCmdSql;
            cache.CommandText = String.Format(
                CultureInfo.CurrentUICulture,
                salesPivotTableQueryTemplate,
                fileName);

            Excel.PivotTable pivotTable = cache.CreatePivotTable(range, pivotTableName, missing, Excel.XlPivotTableVersionList.xlPivotTableVersionCurrent);

            // 将新的数据透视表的属性调整为
            // 所需方式的格式信息。
            pivotTable.ErrorString = " -- ";
            pivotTable.DisplayErrorString = true;
            pivotTable.NullString = " -- ";

            return pivotTable;
        }
开发者ID:jetlive,项目名称:skiaming,代码行数:28,代码来源:ThisWorkbook.cs

示例6: ReportGenerator

        public ReportGenerator(Excel.Worksheet src_worksheet, Excel.Worksheet dest_worksheet)
        {
            _src_worksheet = src_worksheet;
            _dest_worksheet = dest_worksheet;

            writeProjectNamesToDestSheet();
        }
开发者ID:Jeff-Eu,项目名称:WeeklyReportGenerator,代码行数:7,代码来源:ReportGenerator.cs

示例7: PluginManager

        /// <summary/>
        public PluginManager( MSExcel.Application application )
        {
            myApplication = application;

            myPluginContext = new PluginContext( myApplication );
            myPlugins = new List<AbstractPlugin>();
        }
开发者ID:bg0jr,项目名称:Maui,代码行数:8,代码来源:PluginManager.cs

示例8: InsertColumn

        public static void InsertColumn(Excel.Worksheet xlSht, int ColumnNo)
        {
            Excel.Range range = (Excel.Range)xlSht.Cells[1, ColumnNo];
            Excel.Range column = range.EntireColumn;

            column.Insert(Excel.XlInsertShiftDirection.xlShiftToRight, Type.Missing);
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:7,代码来源:ExcelHelper.cs

示例9: protectWS

 private void protectWS(Excel.Worksheet pWS, String pPwdWrite) {
   if((pWS != null) && (pPwdWrite != null)) {
     Object vWritePwd = Type.Missing;
     if(pPwdWrite != null)
       vWritePwd = pPwdWrite;
     pWS.Protect(
       vWritePwd,
       true,
       true,
       true,
       false,
       true,
       true,
       true,
       false,
       false,
       false,
       false,
       false,
       true,
       true,
       true
     );
   }
 }
开发者ID:tormoz70,项目名称:Bio.Framework.8,代码行数:25,代码来源:CExcelSrv_main.cs

示例10: ReleaseExcel

        protected void ReleaseExcel(ref MSOffice.Application excelApp, ref MSOffice.Workbook excelBook, ref MSOffice.Worksheet excelSheet)
        {
            try
            {
                excelBook.Close(false, null, null);
                excelApp.Quit();
                GC.Collect();

                IntPtr ptr = new IntPtr(excelApp.Hwnd);
                int pid = 0;
                GetWindowThreadProcessId(ptr, out pid);
                System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById(pid);

                System.Runtime.InteropServices.Marshal.ReleaseComObject((object)excelApp);
                System.Runtime.InteropServices.Marshal.ReleaseComObject((object)excelBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject((object)excelSheet);
                excelApp = null;
                excelBook = null;
                excelSheet = null;

                //最后尝试结束进程,出错表示已销毁
                try
                { proc.Kill(); }
                catch (Exception) { }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:chanfengsr,项目名称:AllPrivateProject,代码行数:30,代码来源:OfficeInfo.cs

示例11: WriteDataToWorkSheet

        private void WriteDataToWorkSheet(IScriptWorker CurrentScriptWorker, Excel.Worksheet xlWorkSheet, out int RowCounter, out int ColumnCounterForNamesOfTests)
        {
            xlWorkSheet.Cells[1, 1] = "";
            dynamic DatesOfTests = CurrentScriptWorker.GetDatesOfTests();

            RowCounter = 2;
            foreach (dynamic CurrentDate in DatesOfTests)
            {
                xlWorkSheet.Cells[RowCounter, 1] = CurrentDate;
                ++RowCounter;
            }

            dynamic TestsForSave = CurrentScriptWorker.GetListOfTests();
            ColumnCounterForNamesOfTests = 2;         
            foreach (dynamic CurrentTest in TestsForSave)
            {
                xlWorkSheet.Cells[1, ColumnCounterForNamesOfTests] = (string)CurrentTest.GetTestName();
                dynamic CurrentTestResults = CurrentTest.GetValues();
                int RowCounterForTestValues = 2;
                foreach (dynamic CurrentValue in CurrentTestResults)
                {
                    xlWorkSheet.Cells[RowCounterForTestValues, ColumnCounterForNamesOfTests] = CurrentValue;
                    ++RowCounterForTestValues;
                }
                ++ColumnCounterForNamesOfTests;
            }
        }
开发者ID:Saroko-dnd,项目名称:My_DZ,代码行数:27,代码来源:ExcelGraphCreator.cs

示例12: OnCompleted

 protected void OnCompleted(Excel.Workbook xlBook)
 {
     if (Completed != null)
     {
         Completed(this, xlBook);
     }
 }
开发者ID:yangdan8,项目名称:ydERPTY,代码行数:7,代码来源:LotCardExport.cs

示例13: OnSaving

 protected void OnSaving(Excel.Workbook xlBook)
 {
     if (Saving != null)
     {
         Saving(this, xlBook);
     }
 }
开发者ID:yangdan8,项目名称:ydERPTY,代码行数:7,代码来源:LotCardExport.cs

示例14: Sheet

 public Sheet(Excel.Worksheet _worksheet)
 {
     this.Base = _worksheet;
     this.CurrentRow = 1;
     this.CurrentCol = 1;
     this.Valid = ReadValues();
 }
开发者ID:robertvanbuiten,项目名称:cb_testautomation,代码行数:7,代码来源:Sheet.cs

示例15: FrmImport

 public FrmImport(Excel.Application excelapp, CultureInfo culture)
     : base(excelapp)
 {
     _excelapp = excelapp;
     InitializeComponent();
     _ctrlAddress = new[] { ctrlAddress1, ctrlAddress2, ctrlAddress3, ctrlAddress4, ctrlAddress5, ctrlAddress6 };
 }
开发者ID:alnemer,项目名称:excel-qa-tools,代码行数:7,代码来源:FrmImport.cs


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