简体   繁体   English

如何使用C#以编程方式在excel中选择选项卡

[英]how to select the tab in excel programmatically with c#

When I open a workbook in excel it goes to the last tab and scroll position I had open. 当我在excel中打开工作簿时,它会转到最后一个选项卡并滚动我已打开的位置。 I want to write some c# code to open excel workbook and select the first tab, and scroll to cell A1, so when it opens it will be on that that worksheet. 我想编写一些c#代码以打开excel工作簿并选择第一个选项卡,然后滚动到单元格A1,因此当它打开时它将在该工作表上。 all solutions I tried so far produced exceptions: 到目前为止,我尝试过的所有解决方案均产生异常:

worksheet.Select(Type.Missing)
(worksheet as Excel._Worksheet).Activate();
excelApp.Goto(worksheet.get_range("A1", Type.Missing), true);

Try: 尝试:

Microsoft.Office.Interop.Excel.Worksheet firstSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelApp.ActiveWorkbook.Worksheets[1];
firstSheet.Select(System.Reflection.Missing.Value);
excelApp.get_Range("$A1", hmissing).Select();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM