日期:2014-05-17 浏览次数:21080 次
Microsoft.Office.Interop.Excel.Application excel = null; Microsoft.Office.Interop.Excel.Workbook xBook = null; Microsoft.Office.Interop.Excel._Worksheet wks = null; string dataFilePath = System.Environment.CurrentDirectory + @"\Model.xls"; try { excel = new Microsoft.Office.Interop.Excel.Application(); excel.Visible = false; excel.DisplayAlerts = false; //excel.ActivePrinter = "Citizen CLP-521Z"; xBook = excel.Application.Workbooks._Open(dataFilePath, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); if (xBook == null) { xBook = excel.Application.Workbooks.Add(true); } wks = (Microsoft.Office.Interop.Excel._Worksheet)xBook.ActiveSheet; //取得当前worksheet wks.Cells[2, 2] = "'" + sScheduleDate;//.Remove(10); wks.Cells[3, 2] = "'" + sPatientID; wks.Cells[4, 2] = "'" + sName; wks.Cells[5, 2] = "'" + sSex; wks.Cells[5, 4] = "'" + nAge; wks.Cells[6, 2] = "'" + sCheckType; object omo = new object(); //打印预览 //wks.PrintPreview(omo); //不预览打印 wks.PrintOut(1, 1, 1, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //wks.PrintOut(omo, omo, omo, omo, omo, omo, omo, omo); //xBook.Saved = true; xBook.Save(); excel.Application.Workbooks.Close(); excel.Application.Quit(); excel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
------解决方案--------------------
http://apps.hi.baidu.com/share/detail/31171999
http://gbigone.blog.163.com/blog/static/350015292009101831349542/