using Excel=Microsoft.Office.Interop.Excel
private string excelOpenFileName;//操作excel的路径
private int ActiveSheetIndex = 1;//打开工作表的索引
public Excel.Application excelapplication;
public Excel.Workbooks excelworkbooks;
public Excel.workbook excelworkbook;
public Excel.Worksheet excelworksheet;
public Excel.Range excelrange;
public void OpenExcelFile(){
excelapplication = new Excel.ApplicationClass();
excelworkbooks = excelapplication.Workbooks;
excelworkbook = (Excel.Workbook)excelworkbooks.open(excelOpenFileName,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value,Missing.value)
excelworksheet = (Excel.Worksheet)excelworkbook[ActibeSheetIndex];//获取索引位置的工作表,索引不能超出工作表的总数
exclrange = excelworksheet.get_Range("A1","I20")//获取A1到I20的单元格
}
c#.net excel基本步骤
最新推荐文章于 2022-10-26 19:27:57 发布