本文介绍了如何在C#中的Excel文件中识别工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试使用C#读取Excel文件.这是我正在使用的代码:
公共 void method() { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.范围 int rCnt = 0 ; int cCnt = 0 ; xlApp = 新 Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Open( @" 路径" , 0 , true , 5 ," "," " , true ,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows," \ t" ,错误,错误, 0 , true , 1 , 0 ); xlWorkSheet =(Excel.Worksheet)xlWorkBook.Worksheets.get_Item( 4 ); ... .. . }
现在我想根据该工作表的名称阅读特定的工作表.Rite现在这是我用来标识工作表的代码:
xlWorkSheet =(Excel.Worksheet)xlWorkBook.Worksheets.get_Item( 4 );
如何修改此名称,以便可以根据其名称来标识工作表?
在此先感谢!!!
解决方案
Hi all,
I''m trying to read an excel file in C#.This is code i''m using :
public void method() { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; int rCnt = 0; int cCnt = 0; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Open(@"path", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(4); ... .. . }
Now i want to read a particular WorkSheet depending upon the name of that sheet.Rite now this is the code i''m using to identify a worksheet:
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(4);
How can i modify this so that the worksheet can be identified depending upon its name??
Thanks in advance!!!
解决方案
这篇关于如何在C#中的Excel文件中识别工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!