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


C# Workbook.Activate方法代码示例

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


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

示例1: SaveCoordinates

        public void SaveCoordinates(int offset, string injectString)
        {
            String currentFileName = imageFiles[pCurrentImage];
            string ExcelFile = Directory.GetCurrentDirectory() + "\\YourWorkbook.xlsx";

            xlApp.Visible = false;
            xlApp.DisplayAlerts = false;

            if (System.IO.File.Exists(ExcelFile) == false)
            {
                xlApp.Workbooks.Add(Type.Missing);
                aBook1 = xlApp.Workbooks[1];
                aBook1.Activate();
            }
            else
            {
                aBook1 = xlApp.Workbooks.Open(ExcelFile);
            }
            aSheet1 = (excel.Worksheet)aBook1.Sheets[1];

            aRange = (excel.Range)aSheet1.Cells[1, 1];
            aRange.Value2 = "FileName";
            aRange = (excel.Range)aSheet1.Cells[1, 1 + offset];
            aRange.Value2 = "Point" + offset;

            excel.Range last = aSheet1.Cells.SpecialCells(excel.XlCellType.xlCellTypeLastCell, Type.Missing);
            excel.Range range = aSheet1.get_Range("A1", last);

            int lastUsedRow = last.Row;
            int lastUsedColumn = last.Column;

            if (offset == 1)
            {
                lastUsedRow++;
            }
            System.Console.WriteLine("last row {0} ,offset {1}", aSheet1.UsedRange.Rows.Count, offset);

            aRange = (excel.Range)aSheet1.Cells[lastUsedRow, 1];
            aRange.Value2 = Path.GetFileName(currentFileName);

            aRange = (excel.Range)aSheet1.Cells[lastUsedRow, ++offset];
            aRange.Value2 = injectString;

            aSheet1.Application.DisplayAlerts = false;
            aSheet1.Application.AlertBeforeOverwriting = false;

            if (System.IO.File.Exists(ExcelFile) == false)
            {
                aBook1.SaveAs(ExcelFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            }
            else
            {
                aBook1.Save();
            }

            releaseObject(aSheet1);
            releaseObject(aBook1);
            releaseObject(xlApp);

            xlApp.Quit();
        }
开发者ID:hannibal0112,项目名称:CsharpTryOut,代码行数:61,代码来源:Form1.cs


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