• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Interop.Excel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: FastReplace

        public FunctionOutput<string>[] FastReplace(Excel.Range com, DAG dag, InputSample original, InputSample sample, AST.Address[] outputs, bool replace_original)
        {
            FunctionOutput<string>[] fo_arr;
            if (!_d.TryGetValue(sample, out fo_arr))
            {
                // replace the COM value
                ReplaceExcelRange(com, sample);

                // initialize array
                fo_arr = new FunctionOutput<string>[outputs.Length];

                // grab all outputs
                for (var k = 0; k < outputs.Length; k++)
                {
                    // save the output
                    fo_arr[k] = new FunctionOutput<string>(dag.readCOMValueAtAddress(outputs[k]), sample.GetExcludes());
                }

                // Add function values to cache
                // Don't care about return value
                _d.Add(sample, fo_arr);

                // restore the COM value
                if (replace_original)
                {
                    ReplaceExcelRange(com, original);
                }
            }
            return fo_arr;
        }
开发者ID:plasma-umass,项目名称:DataDebug,代码行数:30,代码来源:BootMemo.cs


示例17: ExportPOProjection

        private void ExportPOProjection(WIPItemNeed wipItemNeed, Excel.Worksheet xlSht, int row)
        {
            SortedDictionary<DateTime, float> dictList = new SortedDictionary<DateTime, float>(new IDateTimeDecreaseComparer());

            Dictionary<int, float> dictProj = new Dictionary<int, float>();
            UDFunction.ConvertStringToPromisedDate(POPromisedDateList(wipItemNeed), dictList);
            int dateDiff = 0;

            foreach (KeyValuePair<DateTime, float> kvp in dictList)
            {
                DateTime pDate = (DateTime)kvp.Key;
                float pQty = (float)kvp.Value;
                TimeSpan span = pDate.Subtract(DateTime.Today.AddDays(-1));
                dateDiff = span.Days;

                if (dateDiff < 0)
                    dateDiff = 0;

                if (dateDiff > TOTALDAY)
                    dateDiff = TOTALDAY;

                if (dictProj.ContainsKey(dateDiff))
                    dictProj[dateDiff] = dictProj[dateDiff] + pQty;
                else
                    dictProj.Add(dateDiff, pQty);
            }

            foreach (KeyValuePair<int, float> kvp in dictProj)
            {
                xlSht.Cells[row, COL_STARTDAY + kvp.Key] = kvp.Value;
            }
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:32,代码来源:WIPReport_CM.cs


示例18: GetStations

 private static void GetStations(TrackLayout layout, Excel.Workbook book) {
     Excel.Worksheet sheet = book.Worksheets["StationTrack"];
     var r = 2;
     Station current = null;
     var loop = true;
     while (loop) {
         var row = (Array)sheet.get_Range(Cell("A", r), Cell("G", r)).Cells.Value;
         if (row.GetValue(1, 1) == null) {
             break;
         }
         else {
             var rowType = row.Value(6);
             switch (rowType) {
                 case "Station":
                     if (current != null) layout.Add(current);
                     current = new Station( row.Value(5), row.Value(1));
                    break;
                 case "Track":
                     current.Add(new StationTrack(row.Value(3)));
                     break;
                 default:
                     loop = false;
                     break;
             }
             r++;
         }
     }
     if (current != null) layout.Add(current);
 }
开发者ID:fjallemark,项目名称:TrainDispatch,代码行数:29,代码来源:XplnWithExcelRepository.cs


示例19: InitModuleObjectRanges

 public override void InitModuleObjectRanges(InteropExcel.Workbook ActiveWorkbook, bool AddToWorkbook = false)
 {
     string formula = string.Empty;
     formula = @"=INDIRECT(""_sqlstatements!$A$1:$J""&MAX(1;COUNTA(_sqlstatements!$A$1:$A$5000)))";
     rngp_SqlStatements = new ObjectRange();
     rngp_SqlStatements.InitRange(ActiveWorkbook, "_sqlstatements", "rngSqlstatements", formula, AddToWorkbook);
 }
开发者ID:PSDevGithub,项目名称:PSExcelAddin2010,代码行数:7,代码来源:SqlStatementsModule.cs


示例20: MergeExcels

        internal static void MergeExcels(Excel._Application app,
                                IEnumerable<string> sourcePaths,
                                string destinationPath)
        {
            var dstWb = app.Workbooks.Add("");
            var srcWbs = sourcePaths.Select(sourcePath => app.Workbooks.Add(sourcePath));

            // Don't start with i = 1 because trying to delete the last sheet makes an error.
            for (var i = dstWb.Worksheets.Count; 2 <= i; i--)
            {
                dstWb.Worksheets[i].Delete();
            }

            // Keep the last sheet to be deleted when it is no longer the last sheet.
            Excel.Worksheet ws1 = dstWb.Worksheets[1];

            // app.Workbooks[1] is a destination so needs to be skipped.
            for (var i = app.Workbooks.Count; 2 <= i; i--)
            {
                var srcWb = app.Workbooks[i];
                for (var j = srcWb.Worksheets.Count; 1 <= j; j--)
                {
                    srcWb.Worksheets[j].Copy(dstWb.Worksheets[1]);
                }
            }

            ws1.Delete();
            dstWb.SaveAs(destinationPath);

            foreach (var srcWb in srcWbs)
            {
                srcWb.Close();
            }
        }
开发者ID:tatsuya,项目名称:csharp-utility-library,代码行数:34,代码来源:Excel1.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Excel.Application类代码示例发布时间:2022-05-24
下一篇:
C# Office.Core类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap