Exemple #1
0
        public void StuBaseInfoPrint(Students students, string savePath)
        {
            try
            {
                //创建打印副本
                m_objExcel = new Excel.Application();
                m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
                m_objBook  = (Excel._Workbook)m_objBooks.Open(excelPath + @"report\StudentBaseInfo.xls",
                                                              m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt,
                                                              m_objOpt, m_objOpt, m_objOpt);
                m_objSheets = (Excel.Sheets)m_objBook.Worksheets;

                //获取第一个打印页
                m_objSheet = (Excel._Worksheet)m_objSheets.get_Item(1);

                if (NPrintPicture())
                {
                    m_objPictures = (Excel.Pictures)m_objSheet.Pictures(m_objOpt);
                    m_objPictures.Insert(@"c:\temp.jpg", m_objOpt);
                    m_objPicture = (Excel.Picture)m_objPictures.Item(1);

                    m_objRange          = m_objSheet.get_Range("G8", "H15");
                    m_objPicture.Left   = (double)m_objRange.Left;
                    m_objPicture.Top    = (double)m_objRange.Top;
                    m_objPicture.Width  = (double)m_objRange.Width;
                    m_objPicture.Height = (double)m_objRange.Height;
                }

                //打印园所名字
                m_objRange       = m_objSheet.get_Range("B4", m_objOpt);
                m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString();

                //打印日期
                m_objRange       = m_objSheet.get_Range("G40", m_objOpt);
                m_objRange.Value = DateTime.Now.ToString("yyyy-MM-dd");

                //打印学号
                m_objRange       = m_objSheet.get_Range("B7", m_objOpt);
                m_objRange.Value = students.Number;

                //打印姓名
                m_objRange       = m_objSheet.get_Range("B8", m_objOpt);
                m_objRange.Value = students.Name;

                //打印性别
                m_objRange       = m_objSheet.get_Range("D8", m_objOpt);
                m_objRange.Value = students.Gender;

                //打印出生日
                m_objRange       = m_objSheet.get_Range("F8", m_objOpt);
                m_objRange.Value = students.EntryDate;

                //打印生源
                m_objRange       = m_objSheet.get_Range("B10", m_objOpt);
                m_objRange.Value = students.Origin;

                //打印入托方式
                m_objRange       = m_objSheet.get_Range("D10", m_objOpt);
                m_objRange.Value = students.EntryStatus;

                //打印入园日期
                m_objRange       = m_objSheet.get_Range("F10", m_objOpt);
                m_objRange.Value = students.EntryDate;

                //打印离园日期
                m_objRange = m_objSheet.get_Range("B12", m_objOpt);
                if (students.LeaveDate == DateTime.MinValue)
                {
                    m_objRange.Value = "";
                }
                else
                {
                    m_objRange.Value = students.LeaveDate;
                }

                //打印国籍
                m_objRange       = m_objSheet.get_Range("B18", m_objOpt);
                m_objRange.Value = students.Nationality;

                //打印邮编
                m_objRange       = m_objSheet.get_Range("D18", m_objOpt);
                m_objRange.Value = students.ZipCode;

                //打印街道
                m_objRange       = m_objSheet.get_Range("F18", m_objOpt);
                m_objRange.Value = students.JieDao;

                //打印里委
                m_objRange       = m_objSheet.get_Range("F20", m_objOpt);
                m_objRange.Value = students.LiWei;

                //打印籍贯
                m_objRange       = m_objSheet.get_Range("B20", m_objOpt);
                m_objRange.Value = students.Native;

                //打印家庭住址
                m_objRange       = m_objSheet.get_Range("B22", m_objOpt);
                m_objRange.Value = students.FamilyAddr;

                //打印户口地址
                m_objRange       = m_objSheet.get_Range("B24", m_objOpt);
                m_objRange.Value = students.HuKouAddr;

                //打印病史记录
                m_objRange       = m_objSheet.get_Range("B26", m_objOpt);
                m_objRange.Value = students.SickHistory;

                //打印父亲姓名
                m_objRange       = m_objSheet.get_Range("B31", m_objOpt);
                m_objRange.Value = students.FatherName;

                //打印父亲联系电话
                m_objRange       = m_objSheet.get_Range("F31", m_objOpt);
                m_objRange.Value = students.FatherPhone;

                //打印父亲工作地址
                m_objRange       = m_objSheet.get_Range("B33", m_objOpt);
                m_objRange.Value = students.FatherWorkPlace;

                //打印母亲姓名
                m_objRange       = m_objSheet.get_Range("B35", m_objOpt);
                m_objRange.Value = students.MotherName;

                //打印母亲联系电话
                m_objRange       = m_objSheet.get_Range("F35", m_objOpt);
                m_objRange.Value = students.MotherPhone;

                //打印母亲工作地址
                m_objRange       = m_objSheet.get_Range("B37", m_objOpt);
                m_objRange.Value = students.MotherWorkPlace;

                m_objBook.SaveAs(savePath, m_objOpt, m_objOpt,
                                 m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
                                 m_objOpt, m_objOpt, m_objOpt, m_objOpt);
                m_objBook.Close(false, m_objOpt, m_objOpt);
                m_objExcel.Quit();

                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objRange);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheets);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBooks);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
            }
            catch (Exception e)
            {
                Util.WriteLog(e.Message, Util.EXCEPTION_LOG_TITLE);
            }
            finally
            {
                m_objRange  = null;
                m_objSheet  = null;
                m_objSheets = null;
                m_objBook   = null;
                m_objBooks  = null;
                m_objExcel  = null;

                GC.Collect();

                KillProcess();
            }
        }
		public void PrintTeaBaseInfo(TeacherBase tBase,string savePath)
		{
			try
			{
				m_objExcel = new Excel.Application(); 
				m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;				
				m_objBook = (Excel._Workbook)m_objBooks.Open(excelPath+@"report\TeacherBaseInfo.xls",
							m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,
							m_objOpt,m_objOpt,m_objOpt); 

				m_objSheets = (Excel.Sheets)m_objBook.Worksheets;

				//获取第一个打印页
				m_objSheet = (Excel._Worksheet)m_objSheets.get_Item(1);

				if ( NPrintPicture() )
				{
					m_objPictures = (Excel.Pictures)m_objSheet.Pictures(m_objOpt);
					m_objPictures.Insert(@"c:\temp.jpg",m_objOpt);
					m_objPicture = (Excel.Picture)m_objPictures.Item(1);

					m_objRange = m_objSheet.get_Range("H8","I15");
					m_objPicture.Left = (double)m_objRange.Left;
					m_objPicture.Top = (double)m_objRange.Top;
					m_objPicture.Width = (double)m_objRange.Width;
					m_objPicture.Height = (double)m_objRange.Height;
				}
			
				//园所名
				m_objRange = m_objSheet.get_Range("C6",m_objOpt);
				m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString();

				//打印日期
				m_objRange = m_objSheet.get_Range("H32",m_objOpt);
				m_objRange.Value = DateTime.Now.Date.ToString("yyyy.MM.dd");

				//姓名
				m_objRange = m_objSheet.get_Range("C8",m_objOpt);
				m_objRange.Value = tBase.TName;

				//性别
				m_objRange = m_objSheet.get_Range("E8",m_objOpt);
				m_objRange.Value = tBase.TSex;

				//学历
				m_objRange = m_objSheet.get_Range("G8",m_objOpt);
				m_objRange.Value = tBase.TCareer;

				//家庭电话
				m_objRange = m_objSheet.get_Range("C12",m_objOpt);
				m_objRange.Value = tBase.THomeTel;

				//手机号码
				m_objRange = m_objSheet.get_Range("E12",m_objOpt);
				m_objRange.Value = tBase.TPhone;

				//办公电话
				m_objRange = m_objSheet.get_Range("G12",m_objOpt);
				m_objRange.Value = tBase.TWorkTel;

				//婚否
				m_objRange = m_objSheet.get_Range("C16",m_objOpt);
				m_objRange.Value = tBase.TMerrige;

				//家庭住址
				m_objRange = m_objSheet.get_Range("F16",m_objOpt);
				m_objRange.Value = tBase.TAddr;

				//所属部门
				m_objRange = m_objSheet.get_Range("C20",m_objOpt);
				m_objRange.Value = tBase.TDepart;

				//职务
				m_objRange = m_objSheet.get_Range("F20",m_objOpt);
				m_objRange.Value = tBase.TDuty;

				//职称
				m_objRange = m_objSheet.get_Range("H20",m_objOpt);
				m_objRange.Value = tBase.TTechnicalPost;

				//教师等级
				m_objRange = m_objSheet.get_Range("C24",m_objOpt);
				m_objRange.Value = tBase.TLevel;

				//参加工作时间
				m_objRange = m_objSheet.get_Range("G24",m_objOpt);
				m_objRange.Value = tBase.TWorkTime.ToString("yyyy-MM-dd");
			
				//入园时间
				m_objRange = m_objSheet.get_Range("C28",m_objOpt);
				m_objRange.Value = tBase.TEnterTime.ToString("yyyy-MM-dd");

				m_objBook.SaveAs(savePath, m_objOpt, m_objOpt,
					m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
					m_objOpt, m_objOpt, m_objOpt, m_objOpt);
				m_objBook.Close(false, m_objOpt, m_objOpt);
				m_objExcel.Quit();

				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objRange);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheets);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBooks);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);

			}
			catch(Exception e)
			{
				Util.WriteLog(e.Message,Util.EXCEPTION_LOG_TITLE);
			}
			finally
			{
				m_objRange = null;
				m_objSheet = null;
				m_objSheets = null;
				m_objBook = null;
				m_objBooks = null;
				m_objExcel = null;

				GC.Collect();

				KillProcess();
			}
		}
        public void PrintTeaBaseInfo(TeacherBase tBase, string savePath)
        {
            try
            {
                m_objExcel = new Excel.Application();
                m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
                m_objBook  = (Excel._Workbook)m_objBooks.Open(excelPath + @"report\TeacherBaseInfo.xls",
                                                              m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt,
                                                              m_objOpt, m_objOpt, m_objOpt);

                m_objSheets = (Excel.Sheets)m_objBook.Worksheets;

                //获取第一个打印页
                m_objSheet = (Excel._Worksheet)m_objSheets.get_Item(1);

                if (NPrintPicture())
                {
                    m_objPictures = (Excel.Pictures)m_objSheet.Pictures(m_objOpt);
                    m_objPictures.Insert(@"c:\temp.jpg", m_objOpt);
                    m_objPicture = (Excel.Picture)m_objPictures.Item(1);

                    m_objRange          = m_objSheet.get_Range("H8", "I15");
                    m_objPicture.Left   = (double)m_objRange.Left;
                    m_objPicture.Top    = (double)m_objRange.Top;
                    m_objPicture.Width  = (double)m_objRange.Width;
                    m_objPicture.Height = (double)m_objRange.Height;
                }

                //园所名
                m_objRange       = m_objSheet.get_Range("C6", m_objOpt);
                m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString();

                //打印日期
                m_objRange       = m_objSheet.get_Range("H32", m_objOpt);
                m_objRange.Value = DateTime.Now.Date.ToString("yyyy.MM.dd");

                //姓名
                m_objRange       = m_objSheet.get_Range("C8", m_objOpt);
                m_objRange.Value = tBase.TName;

                //性别
                m_objRange       = m_objSheet.get_Range("E8", m_objOpt);
                m_objRange.Value = tBase.TSex;

                //学历
                m_objRange       = m_objSheet.get_Range("G8", m_objOpt);
                m_objRange.Value = tBase.TCareer;

                //家庭电话
                m_objRange       = m_objSheet.get_Range("C12", m_objOpt);
                m_objRange.Value = tBase.THomeTel;

                //手机号码
                m_objRange       = m_objSheet.get_Range("E12", m_objOpt);
                m_objRange.Value = tBase.TPhone;

                //办公电话
                m_objRange       = m_objSheet.get_Range("G12", m_objOpt);
                m_objRange.Value = tBase.TWorkTel;

                //婚否
                m_objRange       = m_objSheet.get_Range("C16", m_objOpt);
                m_objRange.Value = tBase.TMerrige;

                //家庭住址
                m_objRange       = m_objSheet.get_Range("F16", m_objOpt);
                m_objRange.Value = tBase.TAddr;

                //所属部门
                m_objRange       = m_objSheet.get_Range("C20", m_objOpt);
                m_objRange.Value = tBase.TDepart;

                //职务
                m_objRange       = m_objSheet.get_Range("F20", m_objOpt);
                m_objRange.Value = tBase.TDuty;

                //职称
                m_objRange       = m_objSheet.get_Range("H20", m_objOpt);
                m_objRange.Value = tBase.TTechnicalPost;

                //教师等级
                m_objRange       = m_objSheet.get_Range("C24", m_objOpt);
                m_objRange.Value = tBase.TLevel;

                //参加工作时间
                m_objRange       = m_objSheet.get_Range("G24", m_objOpt);
                m_objRange.Value = tBase.TWorkTime.ToString("yyyy-MM-dd");

                //入园时间
                m_objRange       = m_objSheet.get_Range("C28", m_objOpt);
                m_objRange.Value = tBase.TEnterTime.ToString("yyyy-MM-dd");

                m_objBook.SaveAs(savePath, m_objOpt, m_objOpt,
                                 m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
                                 m_objOpt, m_objOpt, m_objOpt, m_objOpt);
                m_objBook.Close(false, m_objOpt, m_objOpt);
                m_objExcel.Quit();

                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objRange);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheets);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBooks);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
            }
            catch (Exception e)
            {
                Util.WriteLog(e.Message, Util.EXCEPTION_LOG_TITLE);
            }
            finally
            {
                m_objRange  = null;
                m_objSheet  = null;
                m_objSheets = null;
                m_objBook   = null;
                m_objBooks  = null;
                m_objExcel  = null;

                GC.Collect();

                KillProcess();
            }
        }
		public void StuBaseInfoPrint(Students students,string savePath)
		{
			try
			{
				//创建打印副本
				m_objExcel = new Excel.Application();
				m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
				m_objBook = (Excel._Workbook)m_objBooks.Open(excelPath+@"report\StudentBaseInfo.xls",
					m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,m_objOpt,
					m_objOpt,m_objOpt,m_objOpt);
				m_objSheets = (Excel.Sheets)m_objBook.Worksheets;

				//获取第一个打印页
				m_objSheet = (Excel._Worksheet)m_objSheets.get_Item(1);

				if ( NPrintPicture() )
				{
					m_objPictures = (Excel.Pictures)m_objSheet.Pictures(m_objOpt);
					m_objPictures.Insert(@"c:\temp.jpg",m_objOpt);
					m_objPicture = (Excel.Picture)m_objPictures.Item(1);

					m_objRange = m_objSheet.get_Range("G8","H15");
					m_objPicture.Left = (double)m_objRange.Left;
					m_objPicture.Top = (double)m_objRange.Top;
					m_objPicture.Width = (double)m_objRange.Width;
					m_objPicture.Height = (double)m_objRange.Height;
				}

				//打印园所名字
				m_objRange = m_objSheet.get_Range("B4",m_objOpt);
				m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString();

				//打印日期
				m_objRange = m_objSheet.get_Range("G40",m_objOpt);
				m_objRange.Value = DateTime.Now.ToString("yyyy-MM-dd");

				//打印学号
				m_objRange = m_objSheet.get_Range("B7",m_objOpt);
				m_objRange.Value = students.Number;

				//打印姓名
				m_objRange = m_objSheet.get_Range("B8",m_objOpt);
				m_objRange.Value = students.Name;

				//打印性别
				m_objRange = m_objSheet.get_Range("D8",m_objOpt);
				m_objRange.Value = students.Gender;

				//打印出生日
				m_objRange = m_objSheet.get_Range("F8",m_objOpt);
				m_objRange.Value = students.EntryDate;

				//打印生源
				m_objRange = m_objSheet.get_Range("B10",m_objOpt);
				m_objRange.Value = students.Origin;

				//打印入托方式
				m_objRange = m_objSheet.get_Range("D10",m_objOpt);
				m_objRange.Value = students.EntryStatus;

				//打印入园日期
				m_objRange = m_objSheet.get_Range("F10",m_objOpt);
				m_objRange.Value = students.EntryDate;

				//打印离园日期
				m_objRange = m_objSheet.get_Range("B12",m_objOpt);
				if ( students.LeaveDate == DateTime.MinValue )
					m_objRange.Value = "";
				else
					m_objRange.Value = students.LeaveDate;

				//打印国籍
				m_objRange = m_objSheet.get_Range("B18",m_objOpt);
				m_objRange.Value = students.Nationality;

				//打印邮编
				m_objRange = m_objSheet.get_Range("D18",m_objOpt);
				m_objRange.Value = students.ZipCode;

				//打印街道
				m_objRange = m_objSheet.get_Range("F18",m_objOpt);
				m_objRange.Value = students.JieDao;

				//打印里委
				m_objRange = m_objSheet.get_Range("F20",m_objOpt);
				m_objRange.Value = students.LiWei;

				//打印籍贯
				m_objRange = m_objSheet.get_Range("B20",m_objOpt);
				m_objRange.Value = students.Native;

				//打印家庭住址
				m_objRange = m_objSheet.get_Range("B22",m_objOpt);
				m_objRange.Value = students.FamilyAddr;

				//打印户口地址
				m_objRange = m_objSheet.get_Range("B24",m_objOpt);
				m_objRange.Value = students.HuKouAddr;

				//打印病史记录
				m_objRange = m_objSheet.get_Range("B26",m_objOpt);
				m_objRange.Value = students.SickHistory;

				//打印父亲姓名
				m_objRange = m_objSheet.get_Range("B31",m_objOpt);
				m_objRange.Value = students.FatherName;

				//打印父亲联系电话
				m_objRange = m_objSheet.get_Range("F31",m_objOpt);
				m_objRange.Value = students.FatherPhone;

				//打印父亲工作地址
				m_objRange = m_objSheet.get_Range("B33",m_objOpt);
				m_objRange.Value = students.FatherWorkPlace;

				//打印母亲姓名
				m_objRange = m_objSheet.get_Range("B35",m_objOpt);
				m_objRange.Value = students.MotherName;

				//打印母亲联系电话
				m_objRange = m_objSheet.get_Range("F35",m_objOpt);
				m_objRange.Value = students.MotherPhone;

				//打印母亲工作地址
				m_objRange = m_objSheet.get_Range("B37",m_objOpt);
				m_objRange.Value = students.MotherWorkPlace;

				m_objBook.SaveAs(savePath, m_objOpt, m_objOpt,
					m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
					m_objOpt, m_objOpt, m_objOpt, m_objOpt);
				m_objBook.Close(false, m_objOpt, m_objOpt);
				m_objExcel.Quit();

				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objRange);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheets);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBooks);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
				
			}
			catch(Exception e)
			{
				Util.WriteLog(e.Message,Util.EXCEPTION_LOG_TITLE);
			}
			finally
			{
				m_objRange = null;
				m_objSheet = null;
				m_objSheets = null;
				m_objBook = null;
				m_objBooks = null;
				m_objExcel = null;

				GC.Collect();

				KillProcess();
			}
		}