从Excel文件中提取单元格值 [英] To extract cell values from excel file

查看:127
本文介绍了从Excel文件中提取单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的代码将提取一个excel文件的单元格值????
请帮助!!

I want the code that will extract the cell values of an excel file???
Plz help!!!

推荐答案

Herez示例代码可提取excel单元格值:

Herez sample code to extract excel cell value:

Microsoft.Office.Interop.Excel.Worksheet sheet = newWorkbook.ActiveSheet;
  if ( sheet != null ) {
     Microsoft.Office.Interop.Excel.Range range = sheet.UsedRange;
     if ( range != null )
     {
         int nRows = usedRange.Rows.Count;
         int nCols = usedRange.Columns.Count;
         foreach ( Microsoft.Office.Interop.Excel.Range row in usedRange.Rows )
         {
           string value = row.Cells[0].FormattedValue as string;
         }
     }
  } 


using Excel = Microsoft.Office.Interop.Excel;

string FilePath="..\MyFile\Demo.xlsx";  \\ path of your file
         ap = new Excel.Application();  \\ creating instance of excel file
        private Excel.Application ap;
        private Excel.Workbook wb;
        private Excel.Worksheet ws1;

rg1 = ws1.get_Range(ws1.Cells[3, 1],ws1.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,Type.Missing));  \\getting values in range object



在Google上,您可能会找到更有效和更简单的示例.



On google you may find more effective and simple samples.


如果您想在C#/.net中进行操作,上面的代码就足够了.通过读取完整的值范围来应用程序...另一种方法是使用Open XML skd 2.0,它将非常高效并支持标准..
if you want to do it in C#/.net the code above is enough.. but I suggest you can improve the performance of the application by reading the complete range of values... another way is to use Open XML skd 2.0 which will be highly efficient and support the standards..


这篇关于从Excel文件中提取单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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