1. 打开ET文件
ET.Application etApp;
ET.workbook etbook;
ET.Worksheet etsheet;
ET.Range etrange;
etApp = new ET.Application();
etbook = new ET.workbook();
//获取工作表格
etbook = (ET.workbook)etApp.Workbooks.Open(strEtFPath, null, null, null, null, null, null, null, null, null, null, null, null);
//获取第一个表格
etsheet = (ET.Worksheet)etbook.Worksheets.get_Item(1);
//获取数据区域
etrange = (ET.Range)etsheet.UsedRange;
2.关闭ET文件
ET.Application etApp; ET.workbook etbook; ET.Worksheet etsheet; ET.Range etrange; etbook.Close(true, strEtFPath, System.Reflection.Missing.Value); etApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(etrange); System.Runtime.InteropServices.Marshal.ReleaseComObject(etsheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(etbook); System.Runtime.InteropServices.Marshal.ReleaseComObject(etApp);
3.获取ET文件的行数于列数
int iRow = etrange.Rows.Count; int iColumn = etrange.Columns.Count;
4.读取指定位置的数据int iRowCount = 0; int iColumnCount = 0; strData = ((ET.Range)etrange.get_Item(iRowCount, iColumnCount)).Text;
5.创建ET文件
ET.Application etApp; ET.workbook etbook;
ET.Worksheet etsheet;ET.Workbooks etbooks;
etApp = new ET.Application();
etbooks = etApp.Workbooks; etbook = etbooks.Add(System.Reflection.Missing.Value); etsheet = (ET.Worksheet)etbook.ActiveSHeet;