string strFileName = Environment.CurrentDirectory+@"/template/template.tpl";
string strSaveFileName = Environment.CurrentDirectory+@"/excel/"+System.DateTime.Now.ToString().Replace(":","").Replace("-","").Replace(" ","")+@".xls";
Excel.Application ThisApplication = new Excel.ApplicationClass();
Excel.Workbook ThisWorkBook;
object missing = System.Reflection.Missing.Value;
try
{
//加载Excel模板文件
ThisWorkBook = ThisApplication.Workbooks.Open(strFileName,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1];
ThisSheet.Cells[7,1] = dtEnd.ToShortDateString();
progressBar.Value = http://www.jslnfj.com/dnbaike/27529/30;
ThisApplication.Visible = false;
DataRow dr = dt.Rows[0];
for( int i=0; i<dt.Columns.Count;i++)
{
ThisSheet.Cells[7,i+2] = dr[i].ToString();
progressBar.Value +=1;
}
//更新数据后另存为新文件
ThisSheet.SaveAs(strSaveFileName,missing,missing,missing,missing,missing,missing,missing,missing);
}
catch{}
finally
{
ThisApplication.Quit();
ThisWorkBook = null;
ThisApplication = null;
//dt = null;
}
try
{ //打开刚才生成的Excel文件
Excel.Workbook NewWorkBook;
NewWorkBook = NewApplication.Workbooks.Open(strSaveFileName,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);
Excel.Worksheet NewSheet = (Excel.Worksheet)NewWorkBook.Sheets[1];
NewApplication.Visible = true;
//也可以使用System.Diagnostics.Process.Start(strSaveFileName);来打开新文件
【打开一个Excel模板文件填充数据另存为一个文件2020开心玩】 }
推荐阅读
- Excel无法访问-该文档可能为只读或加密文档2020新发布
- 【健康知识】月子里可以喝酒吗
- 你从杜蕾斯文案中学到了什么?
- Excel函数:excel公式把100单元格合并起来欢迎阅读
- Excel-2007让您对数据的大小一目了然2020新发布
- Excel表格自动求差函数公式为你解答
- Excel-2010中设置数值格式新发布的哦
- 如何使Excel-2007用不同颜色显示分类排序筛选后数据欢迎阅读
- excel表格为什么不能筛选猜你喜欢
- siri怎么打开精选视频