//Excel 数据表
string strFileNames = strFileName + ".xlt";
//Excel 路径
strExcelTemplateFile = ConfigurationSettings.AppSettings.GetValues("strExcelTemplateFile")[0];
string strExcelTemplateFiles = strExcelTemplateFile + strFileNames;
excel.Open(strExcelTemplateFiles);//用模板文件
excel.IsVisibledExcel = false;
excel.FormCaption = "报表打印"; //"MIS金质打印通  通打天下报表";
//在模板中写入要打印的数据
Excel.Range range;
if (dt.Rows.Count > 0)
{
//加数据
//AddExcel2(i, j, excel, dt);
for (i = 0; i < dt.Rows.Count; i++)
{
for (j = 0; j < dt.Columns.Count; j++)
{
try
{
string str = dt.Rows[i][j].ToString();
if (j == 0)
{
excel.SetCellText(i + 4, 1, str.Substring(10, 5).ToString().Trim());
excel.SetCellText(i + 4, 2, " ");
}
else
{
excel.SetCellText(i + 4, j +2, str);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}这样打开 Excel 慢慢死了· 那个高手帮帮忙~~~