- string strFileName = "D:\\temp\\aaaa.xls";
- Excel.Application app = new Excel.ApplicationClass();
- Excel.Workbook ThisWorkBook;
- object missing = System.Reflection.Missing.Value;
- app.Visible = false;
- app.UserControl = true;
- Workbooks workbooks = app.Workbooks;
- _Workbook workbook = workbooks.Add(strFileName);//这里的Add方法里的参数就是模板的路径
- Sheets sheets = workbook.Worksheets;
- _Worksheet worksheet = (_Worksheet)sheets.get_Item(1); //这里表示模板只有一个sheet表
- ThisWorkBook = app.Workbooks.Open(strFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
- Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1];
- app.Visible = false;
- worksheet.Cells[5, 8] = name; //写入数据
- worksheet.SaveAs(strSaveFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing);
- worksheet.PrintOut(missing, missing, 1, false, comb.SelectedValue, false, true, "");
- app.Quit(); //清空
- ThisWorkBook = null;
- app = null;
- dt = null;