指引网

当前位置: 主页 > 编程开发 > C >

简单实用的excel编程代码(1/2)

来源:网络 作者:佚名 点击: 时间:2017-07-19 23:04
[摘要] 

private _workbook _workbook = null;
private worksheet _worksheet = null;
private excel.application _excelapplicatin = null;

_excelapplicatin = new excel.application();
_excelapplicatin.visible = true;
_excelapplicatin.displayalerts = true;

_workbook = _excelapplicatin.workbooks.add(xlsheettype.xlworksheet);
_worksheet = (worksheet)_workbook.activesheet;
_worksheet.name = "worksheetname";

//打开已存在的excel
            string strexcelpathname = appdomain.currentdomain.basedirectory + "excelsheetname.xls";
            excel.workbook workbook = application.workbooks.open(strexcelpathname, type.missing, type.missing,
              type.missing, type.missing, type.missing, type.missing, type.missing,
              type.missing, type.missing, type.missing, type.missing, type.missing);
           //读取已打开的excel
            excel.worksheet worksheet1 = (excel.worksheet)workbook.sheets["sheetname1"];
            excel.worksheet worksheet2 = (excel.worksheet)workbook.sheets["sheetname2"];       

            //添加一个worksheet
            worksheet worksheet = (worksheet)workbook.worksheets.add(system.type.missing, system.type.missing, system.type.missing, system.type.missing);

首页 1 2 末页
------分隔线----------------------------