本文整理汇总了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();
}