如何使用C#访问Excel和Excel文件中的不同工作表 [英] How to access different Work Sheets in and Excel file using C#

查看:123
本文介绍了如何使用C#访问Excel和Excel文件中的不同工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
由于我是C#编程的新手,因此我尝试使用此代码行
Microsoft.Office.Interop.Excel.Worksheet workSheet =(Microsoft.Office.Interop.Excel.Worksheet)workBook.ActiveSheet;

这使我可以访问活动工作表.但是有什么方法可以访问文件中特定名称的工作表或任何其他工作表.

Hello,
As i am new to C# programing, i was trying this code line
Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.ActiveSheet;

This gives me access to the active sheet. But is there any way i can access a worksheet of a particular name or any other worksheet in the file. How is the worksheet selection done here and how can i access other work sheets ?

推荐答案

Hai ...

您可以在查询中提及Excel的工作表名称以访问数据.请通过此链接.这会有所帮助...


http://support.microsoft.com/kb/316934
Hai...

U can mention the Sheet name of Excel in a query to access the data. Plz go through this link. It will be helpful...


http://support.microsoft.com/kb/316934


尝试类似的方法


< pre>< code>
Excel.Worksheet tempSheet =(Excel.Worksheet)workBook.Sheets [工作表或工作表标题的索引通常是"Sheet1","Sheet2","Sheet3"等);
</code></pre>
try something like this


<pre><code>
Excel.Worksheet tempSheet = (Excel.Worksheet)workBook.Sheets[index of sheet or Sheet Title usually "Sheet1", ''Sheet2", "Sheet3" etc];
</code></pre>


这篇关于如何使用C#访问Excel和Excel文件中的不同工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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