谁来帮我看下COM组件导出到指定EXCEL模板的代码
OfficeExcelAddInsDom.ExcelAddInsDomFactory.Application = excelApp;
string path = "";
string xlsname = @"jcwmxexcel/接触网表格.xls";
path = Server.MapPath(xlsname);
string filename = SingXzjgSelect1.Textmc + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + ".xls";
//复制文件
string path2 = Server.MapPath(@"jcwmxexcel/") + filename;
File.Copy(path,path2 , true);
excelApp.Workbooks.Open(path2, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
OfficeExcelAddInsDom.ExcelAddInsDom dom = OfficeExcelAddInsDom.ExcelAddInsDomFactory.CreateOfficeExcelAddInsDom();
dom.SetRangeDataTable("接-2", "A4", ds2.Tables[0]); //这里的dom是null 不知道为什么,导致异常找不到实例
dom.SaveDocument(false);
// OpenExcel(filename);
CloseExcel();
this.lbMessage2.InnerHtml = "<a href='jcwmxexcel/" + filename + "' style='color:red; font-weight:bold;'>点击下载excel...</a>";
}
catch (Exception error)
{
CloseExcel();
this.lbMessage2.InnerHtml = "导出失败!";
}