在特定的工作表上打开Excel文件 [英] Open Excel File on a specific worksheet

查看:40
本文介绍了在特定的工作表上打开Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5个工作表的Excel文件,我想用C#代码打开它当它打开时,我希望激活3号工作表.

I have an Excel file with 5 worksheets and I want with c# code to open it and when it is opened I want the sheet number 3 to be activated.

我该怎么做?

推荐答案

像这样:

 using Excel; 

 Excel.Application excelApp = new Excel.ApplicationClass();

  // if you want to make excel visible to user, set this property to true, false by default
  excelApp.Visible = true;

 // open an existing workbook
 string workbookPath = "c:/SomeWorkBook.xls";
    Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
        0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
        true, false, 0, true, false, false);



// get all sheets in workbook
   Excel.Sheets excelSheets = excelWorkbook.Worksheets;

  // get some sheet
 string currentSheet = "Sheet1";
    Excel.Worksheet excelWorksheet = 
        (Excel.Worksheet)excelSheets.get_Item(currentSheet);

 // access cell within sheet
  Excel.Range excelCell = 
        (Excel.Range)excelWorksheet.get_Range("A1", "A1");

希望这会有所帮助

MDSN信息此处

这篇关于在特定的工作表上打开Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆