用c 讀取Excel的方法

2021-04-18 21:54:07 字數 1433 閱讀 7815

用c#讀取excel的方法

public abstract new excel.workbook open ( system.string filename , system.object updatelinks , system.object readonly , system.object format , system.object password , system.object writerespassword , system.object ignorereadonlyrecommended , system.object origin , system.object delimiter , system.object editable , system.object notify , system.object converter , system.object addtomru , system.object local , system.object corruptload )

//這個方法是整個讀取得關鍵,返回乙個工作簿

excel |

| |

||——workbooks |

||___open

當然了,必須在工程中加入相關的com元件

**示例:

object missing=type.missing;

excel.workbook theworkbook =excelobj.workbooks.open(

this.textboxexcelname.text, missing, missing, missing,

missing, missing, missing, missing, missing, missing, missing,

missing,missing);

excel.sheets sheets = theworkbook.worksheets;

excel.worksheet datasheet=null;

foreach(excel.worksheet sheet in sheets)

} if(null==datasheet)

if(""==this.textboxcellfrom.text||""==this.textboxcellto.text)

excel.range range=datasheet.get_range(this.textboxcellfrom.text,this.textboxcellto.text);

system.array myvalues = (system.array)(range.cells.value);//如果只有乙個格(cellfrom==cellto)轉成object即可.

string codes=new string[myvalues.length];

int i=0;

for (i = 1; i <= myvalues.length; i++)

C 讀取EXCEL模版方法

讀取excel模版 filestream fs new filestream tempname,filemode.openorcreate,fileaccess.readwrite hssfworkbook hssfworkbook new hssfworkbook fs isheet sheet ...

C 匯入Excel 讀取Excel方法總結

c 匯入excel 讀取excel方法總結 這種方法一般不用,因為他讀出來的是流,一般是轉成字串 如下 01 02 streamreader sr newstreamreader 檔名以及完整路徑 system.text.encoding.default stringdata sr.readtoen...

C 匯入Excel 讀取Excel方法總結

原文 1.streamreader 方法 這種方法一般不用,因為他讀出來的是流,一般是轉成字串 如下 streamreader sr new streamreader 檔名以及完整路徑 system.text.encoding.default string data sr.readtoend sr....