当前位置: 首页>>代码示例>>C#>>正文


C# Excel.Application.Quit方法代码示例

本文整理汇总了C#中Excel.Application.Quit方法的典型用法代码示例。如果您正苦于以下问题:C# Excel.Application.Quit方法的具体用法?C# Excel.Application.Quit怎么用?C# Excel.Application.Quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Excel.Application的用法示例。


在下文中一共展示了Excel.Application.Quit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetExcelSheetName

        /// <summary>
        /// 读取Excel文件
        /// </summary>
        /// <param name="pPath"></param>
        /// <returns></returns>
      
        private string GetExcelSheetName(string pPath)
        {
            //打开一个Excel应用

            _excelApp = new Excel.Application();
            if (_excelApp == null)
            {
                throw new Exception("打开Excel应用时发生错误!");
            }
            _books = _excelApp.Workbooks;
            //打开一个现有的工作薄
            _book = _books.Add(pPath);
            _sheets = _book.Sheets;
            //选择第一个Sheet页
            _sheet  = (Excel._Worksheet)_sheets.get_Item(1);
            string sheetName = _sheet.Name;

            ReleaseCOM(_sheet);
            ReleaseCOM(_sheets);
            ReleaseCOM(_book);
            ReleaseCOM(_books);
            _excelApp.Quit();
            ReleaseCOM(_excelApp);
            return sheetName;
        }
开发者ID:uwitec,项目名称:gloryview-rfid,代码行数:31,代码来源:ExcelHelper.cs

示例2: NutritionPrint

		public void NutritionPrint(string savePath)
		{
			try
			{
				m_objExcel = new Excel.Application(); 
				m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;				
				m_objBook = (Excel._Workbook)m_objBooks.Open([email protected]"report\nutrition.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;  	
				int number = m_objSheets.Count;	

				writeCover();
				writeStuAmount(); 
	            writeStuConvert();
		        writeACC1(); 
				writeACC2();
				writeElement();	
	
				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 ex)
			{
				Util.WriteLog(ex.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();
			}
		}
开发者ID:zesus19,项目名称:c4.v2.T,代码行数:51,代码来源:FoodManagementPrintRules.cs

示例3: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application xl = new Excel.Application();

            xl.Visible = true;

            xl.Workbooks.Add("c:\\Pasta1.xlt");

            xl.Cells[3, 4] = "oi";

            object x = new object();

            xl.Workbooks[0].Close(false, "", x);

            xl.Quit();
        }
开发者ID:tca85,项目名称:ASP.NET,代码行数:16,代码来源:Form1.cs

示例4: FinanceStatPrint


//.........这里部分代码省略.........
								Convert.ToDouble(objData[data.Rows.Count, column + 3]));
						}
						else if (column == 7)
						{
							double temp1 = Convert.ToDouble(data.Rows[row][column - 4]) + 
								Convert.ToDouble(data.Rows[row][column - 3]) + Convert.ToDouble(data.Rows[row][column - 2]) +
								Convert.ToDouble(data.Rows[row][column - 1]);
							objData[row, column + 3] = temp1;

							double temp2 = Convert.ToDouble(data.Rows[row][column]);
 							objData[row, column + 4] = temp2;
							
							objData[data.Rows.Count, column + 3] = temp1 + (objData[data.Rows.Count, column + 3] == null ? 0 :
								Convert.ToDouble(objData[data.Rows.Count, column + 3]));
							objData[data.Rows.Count, column + 4] = temp2 + (objData[data.Rows.Count, column + 4] == null ? 0 :
								Convert.ToDouble(objData[data.Rows.Count, column + 4]));
						}
						else
						{
							double temp = Convert.ToDouble(data.Rows[row][column]);
							objData[row, column + 4] = temp;
							objData[data.Rows.Count, column + 4] = temp + (objData[data.Rows.Count, column + 4] == null ? 0 :
								Convert.ToDouble(objData[data.Rows.Count, column + 4]));
						}
					}
				}
				m_objRange = m_objSheet.get_Range("A6", m_objOpt);
				m_objRange = m_objRange.get_Resize(data.Rows.Count + 1, data.Columns.Count + 1);
				m_objRange.Value = objData;
				m_objRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
				m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
				m_objRange.WrapText = true;
				m_objRange.Borders.LineStyle = System.Windows.Forms.BorderStyle.FixedSingle;
				m_objRange.Font.Size = 10;

				m_objRange = m_objSheet.get_Range("G3", m_objOpt);
				m_objRange.Value = "各项费用";
				m_objRange = m_objSheet.get_Range(m_objSheet.Cells[3, 7], m_objSheet.Cells[4, data.Columns.Count]);
				m_objRange.Merge(m_objOpt);
				m_objRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
				m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
				m_objRange.WrapText = true;
				m_objRange.Borders.LineStyle = System.Windows.Forms.BorderStyle.FixedSingle;
				m_objRange.Font.Size = 12;

				m_objRange = m_objSheet.get_Range(m_objSheet.Cells[3, data.Columns.Count + 1], m_objSheet.Cells[4, data.Columns.Count + 1]);
				m_objRange.Merge(m_objOpt);
				m_objRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
				m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
				m_objRange.WrapText = true;
				m_objRange.Borders.LineStyle = System.Windows.Forms.BorderStyle.FixedSingle;

				object[, ] objColumn = new object[1, data.Columns.Count - 5];
				for (int column = 3; column < data.Columns.Count - 3; column++ )
				{
					if (column < 7)
					{
						objColumn[0, column - 3] = data.Columns[column].ColumnName;
					}
					if (column == 7)
					{
						objColumn[0, column - 3] = data.Columns[data.Columns.Count - 3].ColumnName;
						objColumn[0, column - 2] = data.Columns[column].ColumnName;
					}
					else
					{
						objColumn[0, column - 2] = data.Columns[column].ColumnName;
					}
				}

				m_objRange = m_objSheet.get_Range("G5", m_objOpt);
				m_objRange = m_objRange.get_Resize(1, data.Columns.Count - 5);
				m_objRange.Value = objColumn;
				m_objRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
				m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
				m_objRange.WrapText = true;
				m_objRange.Borders.LineStyle = System.Windows.Forms.BorderStyle.FixedSingle;
				m_objRange.Font.Size = 10.5;

				for (int column = 5; column < data.Columns.Count - 3; column++)
				{
					m_objRange = m_objSheet.get_Range(m_objSheet.Cells[6, column + 2], m_objSheet.Cells[5 + data.Rows.Count, column + 2]);
					object i = m_objRange.Calculate();
					string s = "asf";
				}
				
				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);
			}
		}
开发者ID:zesus19,项目名称:c4.v2.T,代码行数:101,代码来源:FinanMgmtInfoPrintRules.cs

示例5: RealtimeMorningPrint

		public void RealtimeMorningPrint(DataSet dsRealtimeMorning,string savePath)
		{
			KillProcess();
			try
			{
				m_objExcel = new Excel.Application();
				m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
				m_objBook = (Excel._Workbook)m_objBooks.Open([email protected]"report\RealtimeMorningInfo.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);
				for ( int row = 0; row < dsRealtimeMorning.Tables[0].Rows.Count; row ++ )
				{
                    m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 7, 1], (Excel.Range)m_objSheet.Cells[row + 7, 1]);
					m_objRange.Value = dsRealtimeMorning.Tables[0].Rows[row][1].ToString();
					m_objRange.Borders.LineStyle = BorderStyle.FixedSingle;
					m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
					m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
					m_objRange.Font.Size = 10;
					for ( int column = 3;column < dsRealtimeMorning.Tables[0].Columns.Count; column ++)
					{
                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 7, column - 1], (Excel.Range)m_objSheet.Cells[row + 7, column - 1]);
						m_objRange.set_Item(1,1,dsRealtimeMorning.Tables[0].Rows[row][column].ToString());
						m_objRange.Borders.LineStyle = BorderStyle.FixedSingle;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.Font.Size = 10;
					}

					if ( row == dsRealtimeMorning.Tables[0].Rows.Count - 1 )
					{
                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 9, 1], (Excel.Range)m_objSheet.Cells[row + 9, 1]);
						m_objRange.Value = "园所信息:";
						m_objRange.Font.Bold = true;
						m_objRange.Font.Size = 12;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 9, 2], (Excel.Range)m_objSheet.Cells[row + 9, 2]);
						m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString();
						m_objRange.Font.Size = 12;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 10, 1], (Excel.Range)m_objSheet.Cells[row + 10, 1]);
						m_objRange.Value = "统计日期:";
						m_objRange.Font.Bold = true;
						m_objRange.Font.Size = 12;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 10, 2], (Excel.Range)m_objSheet.Cells[row + 10, 2]);
						m_objRange.Value = DateTime.Now.ToString("yyyy-MM-dd");
						m_objRange.Font.Size = 12;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;

					}
				}

				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();
			}
		}
开发者ID:zesus19,项目名称:c4.v2,代码行数:94,代码来源:RealtimeInfoPrintRules.cs

示例6: ExportToExcel

        /// <summary>
        /// 将 DataTable 导出到 Excel
        /// </summary>
        /// <param name="fOptions"></param>
        public static void ExportToExcel(List<DataTableExportOptions> fOptions, String fFileName)
        {
            if (fOptions == null || fOptions.Count == 0) return;
            #region 判定指定的文件路径下是否存在相同的文件名,如果存在就删除之前的文件
            try
            {

                if (File.Exists(fFileName))
                    File.Delete(fFileName);

            }
            catch
            {
                return;
            }
            #endregion
            Excel.Application application = new Excel.Application();
            application.Visible = false;
            application.UserControl = false;

            Excel.Workbook workBook = (Excel.Workbook)(application.Workbooks.Add(missing));

            try
            {
                #region " 根据需要导出的 DataTable 数量,预先增加不足的工作表或多余的工作表 "

                // 添除多余的工作表
                while (application.ActiveWorkbook.Sheets.Count > fOptions.Count)
                    ((Excel.Worksheet)application.ActiveWorkbook.Sheets[1]).Delete();
                // 添加工作表
                while (application.ActiveWorkbook.Sheets.Count < fOptions.Count)
                    application.Worksheets.Add(missing, missing, missing, missing);

                #endregion

                int sheetIndex = 1;
                List<String> sheetNames = new List<string>();
                foreach (DataTableExportOptions option in fOptions)
                {
                    #region " 处理在多个 DataTable 设置为相同的工作表名称的问题 "

                    if (sheetNames.Contains(option.WorkSheetName))
                    {
                        int i = 1;
                        while (true)
                        {
                            string newSheetName = option.WorkSheetName + i.ToString();
                            if (!sheetNames.Contains(newSheetName))
                            {
                                sheetNames.Add(newSheetName);
                                option.WorkSheetName = newSheetName;
                                break;
                            }
                            i++;
                        }
                    }
                    else
                    {
                        sheetNames.Add(option.WorkSheetName);
                    }

                    #endregion

                    ExportToExcel(application, workBook, (Excel.Worksheet)application.ActiveWorkbook.Sheets[sheetIndex], option);
                    sheetIndex++;
                }

                workBook.SaveAs(fFileName, missing, missing, missing, missing, missing
                    , Excel.XlSaveAsAccessMode.xlExclusive, missing, missing, missing, missing, missing);
            }
            finally
            {
                application.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(application);
                GC.Collect();
            }
        }
开发者ID:treejames,项目名称:HYMES,代码行数:81,代码来源:ExportToExcelProvider.cs

示例7: SaveToExcel


//.........这里部分代码省略.........
                sheet.Cells[1, 9] = "Ten_may";
                sheet.Cells[1, 10] = "Reference_number";
                sheet.Cells[1, 11] = "processing_code";

                //------------FLEXCUBE
                sheet = (Excel._Worksheet)(wb.Sheets[2]);
                ColumnIndex = 0;
                rowIndex = 0;
                foreach (DataRow row in dt2.Rows)
                {
                    rowIndex++;
                    ColumnIndex = 0;
                    foreach (DataColumn col in dt2.Columns)
                    {
                        ColumnIndex++;
                        if (ColumnIndex == 1)
                            sheet.Cells[rowIndex + 1, ColumnIndex] = rowIndex;
                        else
                            sheet.Cells[rowIndex + 1, ColumnIndex] = row[col.ColumnName].ToString();
                        if (ColumnIndex == 6 && row[col.ColumnName].ToString() == "")
                            sheet.Cells[rowIndex + 1, ColumnIndex] = "0";

                    }
                }
                ((Excel.Range)sheet.Cells[1, 7]).EntireColumn.NumberFormat = "d/m/yyyy h:mm:ss";
                ((Excel.Range)sheet.Cells[1, 5]).EntireColumn.NumberFormat = "00000#";

                ((Excel.Range)sheet.Cells[1, 6]).EntireColumn.NumberFormat = "##,##0.00";
                ((Excel.Range)sheet.Cells[1, 3]).EntireColumn.NumberFormat = "##### #### #### #### ####";
                ((Excel.Range)sheet.Cells[1, 4]).EntireColumn.NumberFormat = "########################";
                ((Excel.Range)sheet.Cells[1, 9]).EntireColumn.NumberFormat = "000000";

                // font style
                ((Excel.Range)sheet.Cells[1, 1]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 1]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 2]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 3]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 4]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 5]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 6]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 7]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 8]).Font.Bold = true;
                ((Excel.Range)sheet.Cells[1, 9]).Font.Bold = true;

                sheet.Name = "FLEXCUBE";
                sheet.Cells[1, 1] = "STT";
                sheet.Cells[1, 2] = "LoaiGD";
                sheet.Cells[1, 3] = "Card_number";
                sheet.Cells[1, 4] = "Account_number";
                sheet.Cells[1, 5] = "Trace_number";
                sheet.Cells[1, 6] = "Amount";
                sheet.Cells[1, 7] = "Transaction_date";
                sheet.Cells[1, 8] = "Ten may";
                sheet.Cells[1, 9] = "Processing_code";

                // Let loose control of the Excel instance
                xl.Visible = false;
                xl.UserControl = false;
                // Set a flag saying that all is well and it is ok to save our changes to a file.
                SaveChanges = true;
                //  Save the file to disk
                wb.SaveAs(FileName, Excel.XlFileFormat.xlWorkbookNormal,null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null);
                MessageBox.Show("Export successfull");
            }
            catch (Exception err)
            {
                String msg;
                msg = "Error: ";
                msg = String.Concat(msg, err.Message);
                msg = String.Concat(msg, " Line: ");
                msg = String.Concat(msg, err.Source);
                MessageBox.Show(msg);
            }
            finally
            {
                try
                {
                    // Repeat xl.Visible and xl.UserControl releases just to be sure
                    // we didn't error out ahead of time.
                    xl.Visible = false;
                    xl.UserControl = false;
                    // Close the document and avoid user prompts to save if our method failed.
                    wb.Close(SaveChanges, null, null);
                    xl.Workbooks.Close();
                }
                catch { }
                // Gracefully exit out and destroy all COM objects to avoid hanging instances
                // of Excel.exe whether our method failed or not.
                xl.Quit();
                //if (module != null) { Marshal.ReleaseComObject(module);
            }
            if (sheet != null) { Marshal.ReleaseComObject(sheet); }
            if (wb != null) { Marshal.ReleaseComObject(wb); }
            if (xl != null) { Marshal.ReleaseComObject(xl); }
            //module = null;
            sheet = null;
            wb = null;
            xl = null;
            GC.Collect();
        }
开发者ID:phongferrari,项目名称:banknet-domestic,代码行数:101,代码来源:frmDoiChieuFlexcube.cs

示例8: PrintKidDetailInfo

		public void PrintKidDetailInfo(string getGrade,string getClass,string getName,string getNumber,string savePath)
		{
			try
			{
				DataSet dsStuList_Stat = null;
				DateTime getBegDate = BegDate;
				DateTime getEndDate = EndDate;
				int mbTwoDates = (getEndDate.Year-getBegDate.Year)*12 + (getEndDate.Month-getBegDate.Month);
				int monthes = (getEndDate.Year-getBegDate.Year)*12 + (getEndDate.Month-getBegDate.Month);
				string classInfo = string.Empty;

				using ( StudentCheckInfoDataAccess stuCheckInfoDataAccess = new StudentCheckInfoDataAccess() )
				{
					if ( getName.Equals("") && getNumber.Equals("") )
					{
						dsStuList_Stat = stuCheckInfoDataAccess.GetStuList_GradeClass(getGrade,getClass);
						classInfo = new ClassesDataAccess().GetClassInfo(Convert.ToInt32(getClass),Convert.ToInt32(getGrade)).Tables[0].Rows[0][1].ToString();
					}
					else
					{
						dsStuList_Stat = stuCheckInfoDataAccess.GetStuList_NameNumber(getName,getNumber);
						classInfo = dsStuList_Stat.Tables[0].Rows[0][2].ToString();
					}
				}

				if ( dsStuList_Stat.Tables[0].Rows.Count > 0 )
				{
					m_objExcel = new Excel.Application();
					m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
					m_objBook = (Excel._Workbook)m_objBooks.Open([email protected]"report\MorningCheckInfoKidDetail.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.Sheets;						

					for ( int i=0; i<=monthes; i++ )
					{
						GetExcelEndDate(getBegDate,ref getEndDate);

						m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(i+1));

						if ( mbTwoDates >= 1 )
							m_objSheet.Copy(m_objOpt,m_objSheet);

						m_objRange = m_objSheet.get_Range("AE2",m_objOpt);
						m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString();
						m_objRange = m_objSheet.get_Range("AE3",m_objOpt);
						m_objRange.Value = classInfo;
						m_objRange = m_objSheet.get_Range("AE4",m_objOpt);
						m_objRange.Value = "'" + getBegDate.ToString("yyyy.MM");

						WriteMonth(getBegDate);

						for ( int nameRow=0; nameRow<dsStuList_Stat.Tables[0].Rows.Count; nameRow++ )
						{
							DataSet dsStuCheckInfo_Detail = null;
								
							using ( StudentCheckInfoDataAccess stuCheckInfoDataAccess = new StudentCheckInfoDataAccess() )
							{
								dsStuCheckInfo_Detail = stuCheckInfoDataAccess.GetStuCheckInfo_Detail(dsStuList_Stat.Tables[0].Rows[nameRow][0].ToString(),getBegDate,getEndDate);
								WriteExcelForDetail(getBegDate,getEndDate,dsStuCheckInfo_Detail,nameRow,
									dsStuList_Stat.Tables[0].Rows[nameRow][1].ToString());
							}
						}

						mbTwoDates--;
						getBegDate = getEndDate.AddDays(1);
						getEndDate = EndDate;
					}

					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();
//.........这里部分代码省略.........
开发者ID:zesus19,项目名称:c4.v2,代码行数:101,代码来源:StuMorningCheckInfoPrintRules.cs

示例9: PrintHealth


//.........这里部分代码省略.........
								m_objRange = m_objSheet.get_Range("F17",m_objOpt);
								m_objRange.Value = (getOverW/getSum).ToString();
							}

							break;

							case 3: 
							{
								DataView dvFatStat = dtFatStat.DefaultView;
								dvFatStat.RowFilter = string.Format("info_gradeName = '{0}'", dsGrade.Tables[0].Rows[i][1].ToString());
								if (dvFatStat.Count > 0)
								{
									fatNumber = Convert.ToInt32(dvFatStat[0][1]);
									fatDesc = string.Format("(肥胖{0})", fatNumber);
								}

								m_objRange = m_objSheet.get_Range("G11",m_objOpt);
								m_objRange.Value = dsGrade.Tables[0].Rows[i][1].ToString() + fatDesc;
								m_objRange = m_objSheet.get_Range("G17",m_objOpt);
								m_objRange.Value = getAll(Convert.ToInt32(dsGrade.Tables[0].Rows[i][0]),getBegDate,getEndDate).ToString();
								m_objRange = m_objSheet.get_Range("H17",m_objOpt);
								m_objRange.Value = (getHOPer(Convert.ToInt32(dsGrade.Tables[0].Rows[i][0]),getBegDate,getEndDate) - fatNumber).ToString();
								m_objRange = m_objSheet.get_Range("I17",m_objOpt);
								m_objRange.Value = ((getOverH - fatNumber)/getSum).ToString();                     //身高评测
								m_objRange = m_objSheet.get_Range("J17",m_objOpt);
								m_objRange.Value = getWOPer(Convert.ToInt32(dsGrade.Tables[0].Rows[i][0]),getBegDate,getEndDate).ToString();
								m_objRange = m_objSheet.get_Range("K17",m_objOpt);
								m_objRange.Value = (getOverW/getSum).ToString();
							}
							break;

							case 4: 
							{
								DataView dvFatStat = dtFatStat.DefaultView;
								dvFatStat.RowFilter = string.Format("info_gradeName = '{0}'", dsGrade.Tables[0].Rows[i][1].ToString());
								if (dvFatStat.Count > 0)
								{
									fatNumber = Convert.ToInt32(dvFatStat[0][1]);
									fatDesc = string.Format("(肥胖{0})", fatNumber);
								}

								m_objRange = m_objSheet.get_Range("B20",m_objOpt);
								m_objRange.Value = dsGrade.Tables[0].Rows[i][1].ToString() + fatDesc;
								m_objRange = m_objSheet.get_Range("B26",m_objOpt);
								m_objRange.Value = getAll(Convert.ToInt32(dsGrade.Tables[0].Rows[i][0]),getBegDate,getEndDate).ToString();
								m_objRange = m_objSheet.get_Range("C26",m_objOpt);
								m_objRange.Value = (getHOPer(Convert.ToInt32(dsGrade.Tables[0].Rows[i][0]),getBegDate,getEndDate) - fatNumber).ToString();
								m_objRange = m_objSheet.get_Range("D26",m_objOpt);
								m_objRange.Value = ((getOverH - fatNumber)/getSum).ToString();                     //身高评测
								m_objRange = m_objSheet.get_Range("E26",m_objOpt);
								m_objRange.Value = getWOPer(Convert.ToInt32(dsGrade.Tables[0].Rows[i][0]),getBegDate,getEndDate).ToString();
								m_objRange = m_objSheet.get_Range("F26",m_objOpt);
								m_objRange.Value = (getOverW/getSum).ToString();
							}
							break;
						}	
					}

					DataSet dsWhoTotal = new HealthManagementDataAccess().GetWhoTotal(getBegDate,getEndDate);
					m_objRange = m_objSheet.get_Range("A8",m_objOpt);
					m_objRange.Value = dsWhoTotal.Tables[0].Rows[0][0].ToString();
				
					m_objRange = m_objSheet.get_Range("H28",m_objOpt);
					m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString()+" "+DateTime.Now.ToString("yyyy.MM");

				}

				

				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();
			}
		}
开发者ID:zesus19,项目名称:c4.v2.T,代码行数:101,代码来源:HealthManagementPrintRules.cs

示例10: GenerateReportsByClass

        public void GenerateReportsByClass(string gardenName, DateTime[] dates, Action notify)
        {
            KillProcess();

            var dir = excelPath + @"report\成长记录报表\" + dates[0].ToString("yyyy") + @"\管理员报表";
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            dir += @"\班级统计汇总";
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);
            
            var reportTemplate = new ReportTemplate();
            //按月分组
            foreach(var date in dates)
            {
                var hierarchy = new GrowUpReportDataAccess().GetGrowUpReports(date);
                try
                {
                    foreach (var groupByGrade in hierarchy.Root.GetCollection())
                    {
                        Excel._Worksheet templateSheet = null;
                        m_objExcel = new Excel.Application();
                        m_objExcel.DisplayAlerts = false;
                        m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
                        m_objBook = (Excel._Workbook)m_objBooks.Open(excelPath + @"report\GrowUpReport2.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);
                        foreach (var groupByClass in groupByGrade.Value.GetCollection())
                        {
                            try
                            {
                                m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
                                templateSheet = (Excel._Worksheet)m_objSheets.get_Item(1);
                                var lastSheet = m_objSheets.get_Item(m_objSheets.Count);
                                templateSheet.Copy(m_objOpt, lastSheet);
                                m_objSheet = (Excel._Worksheet)m_objSheets.get_Item(m_objSheets.Count);
                                m_objSheet.Name = string.Format("{0}统计汇总", groupByClass.Key);
                                m_objRange = m_objSheet.get_Range("A1", m_objOpt);
                                m_objRange.Value = string.Format("{0}{1}统计表", gardenName, groupByClass.Key);

                                DoGenerateReportsByClass(groupByGrade.Key, groupByClass.Value, reportTemplate, date);
                            }
                            catch (Exception ex)
                            {
                                Util.WriteLog(ex.Message, Util.EXCEPTION_LOG_TITLE);
                            }
                        }

                        templateSheet.Delete();

                        m_objBook.SaveAs(string.Format("{0}\\{1}统计汇总({2}).xls", dir, groupByGrade.Key, date.ToString("yyyy.MM")), 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);

                        notify();
                    }
                }
                catch (Exception ex)
                {
                    Util.WriteLog(ex.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();
                }
            }
        }
开发者ID:zesus19,项目名称:c4.v2.T,代码行数:86,代码来源:GrowUpReport.cs

示例11: VisitInfoPrint

		public void VisitInfoPrint(DataSet dsAbsDetailInfo,DateTime getBegDate,DateTime getEndDate,string savePath)
		{
			try
			{
				m_objExcel = new Excel.Application(); 
				m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;		
		
				m_objBook = (Excel._Workbook)m_objBooks.Open([email protected]"report\VisitInfo.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);
				
				for ( int row = 0; row < dsAbsDetailInfo.Tables[0].Rows.Count; row ++ )
				{
					for( int column = 1 ;column < dsAbsDetailInfo.Tables[0].Columns.Count-2; column ++)
					{
                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 6, column + 1], (Excel.Range)m_objSheet.Cells[row + 6, column + 1]);
						m_objRange.Value = dsAbsDetailInfo.Tables[0].Rows[row][column].ToString();
						m_objRange.Borders.LineStyle = BorderStyle.FixedSingle;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
					}

					if ( row == dsAbsDetailInfo.Tables[0].Rows.Count - 1 )
					{
                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 8, 2], (Excel.Range)m_objSheet.Cells[row + 8, 3]);
						m_objRange.MergeCells = true;
						m_objRange.Value = "园所信息:";
						m_objRange.Font.Bold = true;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 8, 4], (Excel.Range)m_objSheet.Cells[row + 8, 4]);
						m_objRange.Value = new GardenInfoDataAccess().GetGardenInfo().Tables[0].Rows[0][1].ToString();
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 9, 2], (Excel.Range)m_objSheet.Cells[row + 9, 3]);
						m_objRange.MergeCells = true;
						m_objRange.Value = "统计启始时间:";
						m_objRange.Font.Bold = true;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 9, 4], (Excel.Range)m_objSheet.Cells[row + 9, 4]);
						m_objRange.Value = getBegDate;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 10, 2], (Excel.Range)m_objSheet.Cells[row + 10, 3]);
						m_objRange.MergeCells = true;
						m_objRange.Value = "统计截止时间:";
						m_objRange.Font.Bold = true;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;

                        m_objRange = m_objSheet.get_Range((Excel.Range)m_objSheet.Cells[row + 10, 4], (Excel.Range)m_objSheet.Cells[row + 10, 4]);
						m_objRange.Value = getEndDate;
						m_objRange.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
					}
				}

				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();
			}

		}
开发者ID:zesus19,项目名称:c4.v2,代码行数:97,代码来源:StuVisitInfoPrintRules.cs

示例12: crearExcelReporteStock

        public void crearExcelReporteStock()
        {
            ControlInsumos.DAL.RebajarStockDal rebajarStockDal = new ControlInsumos.DAL.RebajarStockDal();

            string nombreArchivo = "";
            string fecha = cboxAño.Text + "-" + mes();
            dgvInforme.DataSource = b.SelectDataTable(rebajarStockDal.reporteConsumo(fecha));
            switch (mes())
            {
                case "01" : nombreArchivo = "Reporte Consumo Enero " + cboxAño.Text; break;
                case "02" : nombreArchivo = "Reporte Consumo Febrero " + cboxAño.Text; break;
                case "03" : nombreArchivo = "Reporte Consumo Marzo " + cboxAño.Text; break;
                case "04" : nombreArchivo = "Reporte Consumo Abril " + cboxAño.Text; break;
                case "05" : nombreArchivo = "Reporte Consumo Mayo " + cboxAño.Text; break;
                case "06" : nombreArchivo = "Reporte Consumo Junio " + cboxAño.Text; break;
                case "07" : nombreArchivo = "Reporte Consumo Julio " + cboxAño.Text; break;
                case "08" : nombreArchivo = "Reporte Consumo Agosto " + cboxAño.Text; break;
                case "09" : nombreArchivo = "Reporte Consumo Septiembre " + cboxAño.Text; break;
                case "10": nombreArchivo = "Reporte Consumo Octubre " + cboxAño.Text; break;
                case "11": nombreArchivo = "Reporte Consumo Noviembre " + cboxAño.Text; break;
                case "12": nombreArchivo = "Reporte Consumo Diciembre " + cboxAño.Text; break;
                default: break;
            }

            try
            {

                // creating Excel Application

                Excel._Application app = new Excel.Application();

                object misValue = System.Reflection.Missing.Value;

                // creating new WorkBook within Excel application

                Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);

                // creating new Excelsheet in workbook

                Excel._Worksheet worksheet = null;

                // see the excel sheet behind the program
                app.Visible = false;

                // get the reference of first sheet. By default its name is Sheet1.

                // store its reference to worksheet

                worksheet = (Excel._Worksheet)workbook.Sheets["hoja1"];

                //worksheet = (Excel._Worksheet)workbook.ActiveSheet;

                // changing the name of active sheet

                worksheet.Name = "Resumen Consumo";

                // storing header part in Excel

                for (int i = 1; i < dgvInforme.Columns.Count + 1; i++)
                {
                    worksheet.Cells[1, i] = dgvInforme.Columns[i - 1].HeaderText;
                }
                // storing Each row and column value to excel sheet

                for (int i = 0; i < dgvInforme.Rows.Count - 1; i++)
                {
                    for (int j = 0; j < dgvInforme.Columns.Count; j++)
                    {
                        worksheet.Cells[i + 2, j + 1] = dgvInforme.Rows[i].Cells[j].Value.ToString();
                    }
                }

                // save the application
                workbook.SaveAs(nombreArchivo + ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                workbook.Close(true, misValue, misValue);
                MessageBox.Show("El archivo: " + nombreArchivo + ", se ha guardado en Mis Documentos", "Informes", MessageBoxButtons.OK, MessageBoxIcon.Information);

                // Exit from the application

                app.Quit();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
开发者ID:RicardoACS,项目名称:Control_Inventario,代码行数:86,代码来源:informeConsumo.cs

示例13: ConvertXLSToText

        public bool ConvertXLSToText()
        {
            bool result = true;
            Excel.Application oe = new Excel.Application();
            oe.Visible = false;
            oe.EnableEvents = false; //critical to prevent macros from running
            oe.DisplayAlerts = false; //prevents any ui from occuring
            Excel.Workbook wb = oe.Workbooks.Open(SrcFile, 0, false, Missing.Value, "", "", true, Missing.Value, "", false, false, 0, false);
            Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
            if (ws.Name.ToLower() == "cover sheet" || ws.Name.ToLower() == "cover page")
            {
                if (wb.Worksheets.Count > 1)
                {
                    ws = (Excel.Worksheet)wb.Worksheets[2];
                }
            }
            Excel.Range r = ws.UsedRange;
            Array tarray = (Array)r.Value;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(r);

            try
            {
                int rows = tarray.GetUpperBound(0);
                int columns = tarray.GetUpperBound(1);
                bool lineBlank;
                string tempValue;
                string Line;
                StringBuilder Lines = new StringBuilder(1);
                for (int rc = 0; rc < rows; rc++)
                {
                    lineBlank = true;
                    Line = "";
                    for (int c = 0; c < columns; c++)
                    {
                        try
                        {
                            tempValue = tarray.GetValue(rc + 1, c + 1).ToString();
                        }
                        catch (Exception)
                        {
                            tempValue = "";
                        }
                        Line += tempValue + (((c + 1) == columns) ? "" : "\t");
                        if (tempValue.Trim() != "")
                        {
                            lineBlank = false;
                        }
                    }
                    if (!lineBlank)
                    {
                        Lines.Append(Line + "\r\n");
                    }
                }
                wb.Close(false, Missing.Value, Missing.Value);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
                oe.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oe);
                result = WriteToDestFile(Lines);
            }
            catch (Exception ex)
            {
                result = false;
                _lasterror = ex.Message.Split('\n')[0];
            }
            return result;
        }
开发者ID:pravastech,项目名称:IntelWebMap,代码行数:67,代码来源:FileConverter.cs

示例14: ImportCardExcelFile

		public void ImportCardExcelFile(string id,string name,string grade,
			string atClass,bool isStu,string savePath)
		{
			if(grade.Equals("全部"))
			{
				grade = string.Empty;
			}

			if(atClass.Equals("全部"))
			{
				atClass = string.Empty;
			}

			DataSet cardInfo;
			object[,] objData;
			
			string excelTempFilePath = AppDomain.CurrentDomain.BaseDirectory;

			Excel.Application m_objExcel = null;
			Excel.Workbooks m_objBooks = null;
			Excel._Workbook m_objBook = null;
			Excel.Sheets m_objSheets = null;
			Excel._Worksheet m_objSheet = null;
			Excel.Range m_objRange = null;
			Excel.Font m_objFont = null;
			System.Reflection.Missing m_objOpt = System.Reflection.Missing.Value;

			try
			{
				if(isStu)
				{
					using(CardInfoDA cardInfoDA = new CardInfoDA())
					{
						cardInfo = cardInfoDA.GetStuCardNumberForExcel(id,name,grade,atClass);
					}

					if(cardInfo.Tables[0].Rows.Count>0)
					{
						objData = new Object[cardInfo.Tables[0].Rows.Count,7];

						for(int i=0;i<cardInfo.Tables[0].Rows.Count;i++)
						{
							objData[i,0] = cardInfo.Tables[0].Rows[i][0].ToString();
							objData[i,1] = cardInfo.Tables[0].Rows[i][1].ToString();
							objData[i,2] = cardInfo.Tables[0].Rows[i][2].ToString();
							objData[i,3] = cardInfo.Tables[0].Rows[i][3].ToString();
							objData[i,4] = cardInfo.Tables[0].Rows[i][4].ToString();
							objData[i,5] = cardInfo.Tables[0].Rows[i][5].ToString();
							objData[i,6] = cardInfo.Tables[0].Rows[i][6].ToString();			
						}

						m_objExcel = new Excel.Application();
						m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
						m_objBook = (Excel._Workbook)m_objBooks.Open([email protected]"report\StudentCardInfo.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.Sheets;
						m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(1));
						m_objRange = m_objSheet.get_Range("A3",m_objOpt);
						m_objRange = m_objRange.get_Resize(cardInfo.Tables[0].Rows.Count,7);

						m_objRange.Value = objData;

						m_objRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
						m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
						m_objRange.WrapText = true;
						m_objRange.Borders.LineStyle = System.Windows.Forms.BorderStyle.FixedSingle;
						m_objFont = m_objRange.Font;
						m_objFont.Size = 9;

						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_objFont);
						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);
					}
				}
				else
				{
					using(CardInfoDA cardInfoDA = new CardInfoDA())
					{
						cardInfo = cardInfoDA.GetTeaCardNumberForExcel(id,name,grade,atClass);
					}

					if(cardInfo.Tables[0].Rows.Count>0)
					{
						objData = new Object[cardInfo.Tables[0].Rows.Count,6];

						for(int i=0;i<cardInfo.Tables[0].Rows.Count;i++)
						{
							objData[i,0] = cardInfo.Tables[0].Rows[i][0].ToString();
//.........这里部分代码省略.........
开发者ID:zesus19,项目名称:c4.v2.T,代码行数:101,代码来源:CardInfoRule.cs

示例15: WriteCardInfoExcel


//.........这里部分代码省略.........

					for (int row = 0; row < dsCardInfo.Tables[0].Rows.Count; row++)
					{
						objData[row + 1, 0] = dsCardInfo.Tables[0].Rows[row][0];
						objData[row + 1, 1] = dsCardInfo.Tables[0].Rows[row][1];
						objData[row + 1, 2] = dsCardInfo.Tables[0].Rows[row][2];
						objData[row + 1, 3] = dsCardInfo.Tables[0].Rows[row][3];
					}

					foreach(DataRow row in dsCardInfo.Tables[2].Rows)
					{
						objData[index + 1, 5] = row[1];
						index += Convert.ToInt32(row[1]);
					}

					m_objRange = m_objSheet.get_Range("A1",m_objOpt);
					m_objRange = m_objRange.get_Resize(dsCardInfo.Tables[0].Rows.Count + 4,6);
					m_objRange.Value = objData;
					m_objRange.Font.Size = 8;
					m_objRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
					m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;	

					RowMerge("A", dsCardInfo.Tables[1]);
					RowMerge("B", dsCardInfo.Tables[2]);
					RowMerge("C", dsCardInfo.Tables[3]);
					RowMerge("F", dsCardInfo.Tables[2]);

					m_objRange = m_objSheet.get_Range("A" + (dsCardInfo.Tables[0].Rows.Count + 2).ToString(),
						"A" + (dsCardInfo.Tables[0].Rows.Count + 2).ToString());
					m_objRange.Value = "空卡";
					m_objRange = m_objSheet.get_Range("B" + (dsCardInfo.Tables[0].Rows.Count + 2).ToString(),
						"B" + (dsCardInfo.Tables[0].Rows.Count + 2).ToString());
					m_objRange.Value = GetCardEncryptedNumber() - Convert.ToInt32(dsCardInfo.Tables[4].Rows[0][0]) 
						- Convert.ToInt32(dsCardInfo.Tables[5].Rows[0][0]);
					m_objRange = m_objSheet.get_Range("A" + (dsCardInfo.Tables[0].Rows.Count + 3).ToString(),
						"A" + (dsCardInfo.Tables[0].Rows.Count + 3).ToString());
					m_objRange.Value = "学生卡";
					m_objRange = m_objSheet.get_Range("B" + (dsCardInfo.Tables[0].Rows.Count + 3).ToString(),
						"B" + (dsCardInfo.Tables[0].Rows.Count + 3).ToString());
					m_objRange.Value = dsCardInfo.Tables[4].Rows[0][0];
					m_objRange = m_objSheet.get_Range("A" + (dsCardInfo.Tables[0].Rows.Count + 4).ToString(),
						"A" + (dsCardInfo.Tables[0].Rows.Count + 4).ToString());
					m_objRange.Value = "教师卡";
					m_objRange = m_objSheet.get_Range("B" + (dsCardInfo.Tables[0].Rows.Count + 4).ToString(),
						"B" + (dsCardInfo.Tables[0].Rows.Count + 4).ToString());
					m_objRange.Value = dsCardInfo.Tables[5].Rows[0][0];

					m_objRange.get_Range("B" + (dsCardInfo.Tables[0].Rows.Count + 2).ToString(),
						"F" + (dsCardInfo.Tables[0].Rows.Count + 2).ToString()).Merge(m_objOpt);

					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();
	
				}
			}
			catch(Exception ex)
			{
				throw ex;
			}
			finally
			{
				if (m_objRange != null)
				{
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objRange);
					m_objRange = null;
				}
				if (m_objSheet != null)
				{
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
					m_objSheet = null;
				}
				if (m_objSheets != null)
				{
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheets);
					m_objSheets = null;
				}
				if (m_objBook != null)
				{
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);
					m_objBook = null;
				}
				if (m_objBooks != null)
				{
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBooks);
					m_objBooks = null;
				}
				if(m_objExcel != null)
				{
					System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
					m_objExcel = null;
				}

				GC.Collect();

				KillProcess();
			}
		}
开发者ID:zesus19,项目名称:c4.v2.T,代码行数:101,代码来源:CardInfoRule.cs


注:本文中的Excel.Application.Quit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。