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


C# Application.Quit方法代码示例

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


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

示例1: ConvertToWordDocument

        internal void ConvertToWordDocument(string pathToRtfFile)
        {
            Document currentDoc = null;
            Application wordApp = null;
            try
            {
                var filename = string.Format("{0}.docx", Path.GetFileNameWithoutExtension(pathToRtfFile));
                var fullFilePath = string.Format("{0}\\{1}", _savePath, filename);

                wordApp = new Application();
                currentDoc = wordApp.Documents.Open(pathToRtfFile);

                Debug.WriteLine("Saving file: '{0}'", fullFilePath, null);
                currentDoc.SaveAs(fullFilePath, WdSaveFormat.wdFormatXMLDocument);
                Debug.WriteLine("Saved file: '{0}'", fullFilePath, null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("An exception occurred while saving a file: '{0}'", ex.Message, null);
            }
            finally
            {
                if (currentDoc != null)
                {
                    currentDoc.Close();
                }
                if (wordApp != null)
                {
                    wordApp.Quit();
                }
            }
        }
开发者ID:Jandev,项目名称:bookrepotoepub,代码行数:32,代码来源:OfficeWorker.cs

示例2: WriteToFile

        public void WriteToFile(string _fileName, IEnumerable<Link> _links)
        {
            Application application = new Application();
            application.Visible = true;
            application.DisplayAlerts = false;

            Workbook workbook = application.Workbooks.Add();
            Worksheet worksheet = workbook.Worksheets.get_Item(1);

            worksheet.Cells[1, 1] = "From";
            setBorders(worksheet, "A1");
            worksheet.Cells[1, 2]= "To";
            setBorders(worksheet, "B1");
            worksheet.Cells[1, 3] = "Distance";
            setBorders(worksheet, "C1");
            worksheet.Cells[1, 4] = "Mode";
            setBorders(worksheet, "D1");

            int curRow = 2;
            foreach(Link l in _links)
            {
                worksheet.Cells[curRow, 1] = l.FromCity.Name + " ("+l.FromCity.Country+")";
                worksheet.Cells[curRow, 2] = l.ToCity.Name + " (" + l.ToCity.Country + ")";
                worksheet.Cells[curRow, 3] = l.Distance;
               // TransportMode mode = l.TransportMode;
                worksheet.Cells[curRow, 4] = Enum.GetName(typeof(TransportMode), l.TransportMode);
                curRow++;
            }

            worksheet.Columns.AutoFit();

            workbook.SaveAs(_fileName);

            application.Quit();
        }
开发者ID:Laubeee,项目名称:ecnf,代码行数:35,代码来源:ExcelExchange.cs

示例3: GetEnumerator

        public override IEnumerator<IDataSheet> GetEnumerator()
        {
            Info.Refresh();
            if (!Info.Exists)
            {
                yield break;
            }

            Application instance = null;
            try
            {
                instance = new Application();
                var workbook = instance.Workbooks.Open(Info.FullName, 0, true, 5, string.Empty, string.Empty, true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                foreach (_Worksheet sheet in workbook.Sheets)
                {
                    yield return new ExcelWorksheet(Info, sheet);
                }
            }
            finally
            {
                if (null != instance)
                {
                    instance.Quit();
                }
            }
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:26,代码来源:ExcelWorkbook.cs

示例4: Main

        static void Main(string[] args)
        {
            string filename = @"d:\excel1\myfile.xls";

            Application objExcel = new Application();
            Workbook workBook = objExcel.Workbooks.Add(Missing.Value);
            if (!File.Exists(filename))
            {
                workBook.SaveAs(filename, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, XlSaveAsAccessMode.xlExclusive, Missing.Value,
    Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            }
            else
            {
                workBook = objExcel.Workbooks.Open(filename, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            }
            Sheets sheets = workBook.Worksheets;
            Worksheet worksheet = (Worksheet)sheets.get_Item(1);
            worksheet.get_Range("A1", Missing.Value).Value2 = "A";
            worksheet.get_Range("A2", Missing.Value).Value2 = "B";
            worksheet.get_Range("A3", Missing.Value).Value2 = "C";
            worksheet.get_Range("A4", Missing.Value).Value2 = "D";
            worksheet.get_Range("A5", Missing.Value).Value2 = "E";
            Range range = worksheet.get_Range("A1", "A5");
            range.Sort(range.Columns[1,Missing.Value], XlSortOrder.xlDescending, Missing.Value, Missing.Value, XlSortOrder.xlAscending, Missing.Value, XlSortOrder.xlAscending, XlYesNoGuess.xlGuess, Missing.Value, Missing.Value, XlSortOrientation.xlSortColumns, XlSortMethod.xlPinYin, XlSortDataOption.xlSortNormal, XlSortDataOption.xlSortNormal, XlSortDataOption.xlSortNormal);

            workBook.Save();
            objExcel.Quit();
            
        }
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:29,代码来源:Program.cs

示例5: WriteToExcel

    public static Boolean WriteToExcel(GridView gridView)
    {
        try
        {
            if (gridView != null)
            {
                Application excel = new Application();
                Workbook book = excel.Workbooks.Add(true);
                Worksheet sheek = book.Worksheets[1] as Worksheet;
                sheek.Columns.ColumnWidth = 15;

                int rowIndex = 1;
                int colIndex = 1;

                for (int i = 0; i < gridView.HeaderRow.Cells.Count; i++)
                {
                    Range headRange = excel.Cells[1, colIndex] as Range;
                    headRange.Value = gridView.HeaderRow.Cells[i].Text.ToString();
                    headRange.HorizontalAlignment = XlHAlign.xlHAlignCenter;
                    headRange.Borders.LineStyle = XlLineStyle.xlContinuous;
                    headRange.Interior.Color = Color.Red;
                    colIndex++;
                }

                foreach (GridViewRow row in gridView.Rows)
                {
                    rowIndex++;
                    colIndex = 1;
                    for (int i = 0; i < row.Cells.Count; i++)
                    {
                        Range contentRange = excel.Cells[rowIndex, colIndex] as Range;
                        contentRange.Value = row.Cells[i].Text.ToString();
                        contentRange.HorizontalAlignment = XlHAlign.xlHAlignCenter;
                        contentRange.Borders.LineStyle = XlLineStyle.xlContinuous;
                        colIndex++;
                    }

                }

                excel.DisplayAlerts = false;
                excel.Save();
                excel.Quit();

                return true;
            }
            else
                return false;

        }
        catch (Exception)
        {
            return false;
        }
    }
开发者ID:smilelhh,项目名称:-web-,代码行数:54,代码来源:ExcelUtil.cs

示例6: Convert

        /// <summary>
        /// конвертация
        /// </summary>
        /// <param name="fileName">путь к файлу</param>
        /// <returns>путь к созданному файлу</returns>
        public static string Convert(string fileName)
        {
            string newFileName = DocToDocxConverter.ConvertDocToDocx(fileName);
            try
            {
                _Application wordApplication = new Application();
                wordApplication.Visible = false;

                _Document wordDocument = wordApplication.Documents.Open(newFileName);
                string pdfResultName = Path.ChangeExtension(newFileName, "pdf");
                //pdfResultName = FileHelper.GetNotUsedFileName(pdfResultName);

                wordDocument.ExportAsFixedFormat(pdfResultName, WdExportFormat.wdExportFormatPDF, CreateBookmarks: WdExportCreateBookmarks.wdExportCreateHeadingBookmarks);

                object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
                wordDocument.Close(saveChanges, oMissing, oMissing);

                wordApplication.Quit(ref oMissing, ref oMissing, ref oMissing);
                wordApplication = null;
                return pdfResultName;
            }
            catch
            {
                throw new NotSupportedException("При конвертации произошла ошибка");
            }
        }
开发者ID:ssementsov,项目名称:PrintBook,代码行数:31,代码来源:WordToPdfConverter.cs

示例7: ExportExcel

 /// <summary>   
 /// 直接导出Excel   
 /// </summary>   
 /// <param name="datatable">数据源DataSet</param>   
 /// <param name="fileName">保存文件名(例如:E:\a.xls)</param>   
 /// <returns></returns>   
 public static bool ExportExcel(System.Data.DataTable datatable, string fileName)
 {
     if (datatable.Rows.Count < 0 || fileName == string.Empty)
     {
         return false;
     }
     Application excel = new Application();
     int rowindex = 1;
     int colindex = 0;
     Workbook work = excel.Workbooks.Add(true);
     foreach (DataColumn col in datatable.Columns)
     {
         colindex++;
         excel.Cells[1, colindex] = GetColName(col.ColumnName);
     }
     foreach (DataRow row in datatable.Rows)
     {
         rowindex++;
         colindex = 0;
         foreach (DataColumn col in datatable.Columns)
         {
             colindex++;
             excel.Cells[rowindex, colindex] = row[col.ColumnName].ToString();
         }
     }
     excel.Visible = false;
     excel.ActiveWorkbook.Saved = true;
     excel.ActiveWorkbook.SaveCopyAs(fileName);
     excel.Quit();
     excel = null;
     GC.Collect();
     return true;
 }
开发者ID:penzz,项目名称:FTPMonitor,代码行数:39,代码来源:ExcelOperate.cs

示例8: ConvertWord_To_Pdf

 public void ConvertWord_To_Pdf()
 {
     var appWord = new Application();
     var wordDocument = appWord.Documents.Open(@"C:\Users\SimonMarkey\Desktop\TestWord2.docx");
     wordDocument.ExportAsFixedFormat(@"C:\Users\SimonMarkey\Desktop\TestWord.pdf", WdExportFormat.wdExportFormatPDF);
     wordDocument.Close();
     appWord.Quit();
 }
开发者ID:Foxpips,项目名称:Algorithms,代码行数:8,代码来源:WordDocTests.cs

示例9: BuildeDocument

        public void BuildeDocument(CnRecipientInfo cnRecipientInfo, int kg, string docFilePath, bool IsPrintRequired = false)
        {
            this.cnRecipientInfo = cnRecipientInfo;
            this.kg = kg;

            Object Nothing = System.Reflection.Missing.Value;
            Application WordApp = new Application();
            Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

            WordDoc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
            WordApp.Selection.Font.Name = "微软雅黑";
            WordApp.Selection.Font.Size = this.fontSize;
            WordApp.Selection.Font.Scaling = 100;
            WordApp.Selection.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly;
            WordApp.Selection.ParagraphFormat.LineSpacing = 20;

            WordApp.Selection.TypeText("亲爱的快递员,您辛苦了~!累了就休息休息~注意身体~");
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.Font.Size = 8f;
            WordApp.Selection.TypeText(new string('-',120));
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.Font.Size = this.fontSize; ;
            WordApp.Selection.TypeText(string.Format("邮编:\t\t{0}", this.cnRecipientInfo.PostCode));            
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.TypeText(string.Format("地址:\t\t{0}", this.cnRecipientInfo.Address));
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.TypeText(string.Format("收件人:\t\t{0} \t\t\t\t{1}", this.cnRecipientInfo.Name, this.cnRecipientInfo.Name.NameToPinyin()));
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.TypeText(string.Format("电话:\t\t{0}", this.cnRecipientInfo.TelListText));
            WordApp.Selection.Font.Size = 8f;
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.TypeText(new string('-', 120));
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.TypeText("★ 祝愿宝宝与妈妈开心快乐每一天 ☆ 也祝快递员天天开心:)★ ");
            WordApp.Selection.TypeParagraph();

            WordApp.Selection.TypeParagraph();
 
            object filename = Path.Combine(docFilePath, string.Format("{0} {1} 地址.doc",this.cnRecipientInfo.Name, DateTime.Now.ToString("MM-dd_HHmmss")));

            WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);

            if (IsPrintRequired) WordDoc.PrintOut();
            
            WordDoc.Close(Type.Missing, Type.Missing, Type.Missing);
            WordApp.Quit(Type.Missing, Type.Missing, Type.Missing);


        }
开发者ID:cotopboy,项目名称:nxdaigou_git,代码行数:56,代码来源:CnRecipientLabelBuilder.cs

示例10: Main

        static void Main(string[] args)
        {
            InitEntityResolver();
            app = new Application();

            foreach (string file in args)
            {
                ProcessFile(file);
            }

            app.Quit();
        }
开发者ID:posinaga,项目名称:word-redactor,代码行数:12,代码来源:Program.cs

示例11: reformatBillTextToWord

 private static void reformatBillTextToWord(string fileName)
 {
     var word = new Application();
     word.Visible = true;
     var doc = word.Documents.Open(fileName, Encoding:866, NoEncodingDialog: true);
     doc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
     doc.PageSetup.LeftMargin = 25;
     doc.PageSetup.RightMargin = 25;
     doc.PageSetup.TopMargin = 25;
     doc.PageSetup.BottomMargin = 25;
     doc.Range().Font.Size = 9;
     doc.SaveAs(fileName + @".doc", WdSaveFormat.wdFormatDocument);
     word.Quit();
 }
开发者ID:vvboborykin,项目名称:VistaMedTools,代码行数:14,代码来源:WordReportBuilder.cs

示例12: SaveSheetsIntoDiffTxtFiles

 public void SaveSheetsIntoDiffTxtFiles(SaveFileFormat FileFormat)
 {
     var excel = new Application();
     var workBook = excel.Application.Workbooks.Open(ExcelFilePath);
     excel.Visible = false;
     excel.DisplayAlerts = false;
     var workBookName = workBook.Name;
     //workBook.SaveAs(ExportFilesSavePath + "\\" + "4", XlFileFormat.,Type.Missing,Type.Missing,Type.Missing,Type.Missing,XlSaveAsAccessMode.xlExclusive,Type.Missing,Type.Missing,Type.Missing,XlTextVisualLayoutType.xlTextVisualLTR,Type.Missing);
     var workSheets = workBook.Sheets;
     foreach(Microsoft.Office.Interop.Excel.Worksheet workSheet in workSheets)
     {
         workSheet.SaveAs(ExportFilesSavePath + "\\" + workBookName + "_" + workSheet.Name + "."+FileFormat.ToString().ToLower(), XlFileFormat.xlTextPrinter);
     }
     workBook.Save();
     excel.Quit();
 }
开发者ID:CasparCui,项目名称:Report.Load,代码行数:16,代码来源:LoadXlsxData.cs

示例13: Create

        public static void Create(string file, string author)
        {
            // Create word app and bind to a dynamic variable
            dynamic app = new Application { Visible = true };

            // Create document
            var doc = app.Documents.Add();
            string text = "Hello, this is anytao. /" + DateTime.Now.ToString();

            dynamic range = doc.Range(0, 0);
            range.Text = text;

            // Save document
            doc.SaveAs(file);
            app.Quit();
        }
开发者ID:anytao,项目名称:insidenet,代码行数:16,代码来源:DynamicWord.cs

示例14: Read

        public System.Data.DataTable Read(string path)
        {
            Application _excelApp = new Application();

            //open the workbook
            Workbook workbook = _excelApp.Workbooks.Open(path,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                Type.Missing, Type.Missing);

            //select the first sheet        
            Worksheet worksheet = (Worksheet)workbook.Worksheets[1];

            //find the used range in worksheet
            Range excelRange = worksheet.UsedRange;

            //get an object array of all of the cells in the worksheet (their values)
            object[,] valueArray = (object[,])excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault);

            System.Data.DataTable records = new System.Data.DataTable();

            //access the cells
            for (int row = 1; row <= worksheet.UsedRange.Rows.Count; ++row)
            {
                DataRow dataRow = records.NewRow();
                for (int col = 1; col <= worksheet.UsedRange.Columns.Count; ++col)
                {
                    if (row == 1)
                        records.Columns.Add(valueArray[row, col].ToString().ToUpper().Trim(), valueArray[row, col].GetType());
                    else
                        dataRow[col - 1] = valueArray[row, col];
                }

                if (row > 1)
                    records.Rows.Add(dataRow);
            }

            //clean up stuffs
            workbook.Close(false, Type.Missing, Type.Missing);
            Marshal.ReleaseComObject(workbook);

            _excelApp.Quit();
            Marshal.FinalReleaseComObject(_excelApp);

            return records;
        }
开发者ID:macrodepy,项目名称:Macro.Common,代码行数:47,代码来源:Excel.cs

示例15: Print

        public void Print(string filename, List<string> headers, List<List<string>> table)
        {
            if (headers.Count != table.First().Count)
            {
                throw new Exception("Table size and headers size must be equal");
            }
            Application excelApp = new Application();
            var fullFileName = Path.GetFullPath(filename + ".xlsx");
            var workBook = excelApp.Workbooks.Add(System.Reflection.Missing.Value);
            excelApp.Columns.HorizontalAlignment = Constants.xlCenter;

            for (int colNum = 1; colNum <= headers.Count; ++colNum)
            {
                excelApp.Cells[1, colNum] = headers[colNum - 1];
            }

            int rowNum = 2;
            foreach (var row in table)
            {
                for (int colNum = 1; colNum <= row.Count; ++colNum)
                {
                    excelApp.Cells[rowNum, colNum] = row[colNum - 1];
                }
                rowNum++;
            }

            excelApp.Columns.AutoFit();

            File.Delete(fullFileName);

            try
            {
                workBook.SaveAs(fullFileName);
            }
            finally
            {
                workBook.Close(false);

                excelApp.Quit();

                workBook = null;
                excelApp = null;
                GC.Collect();
            }
        }
开发者ID:WinMustDie,项目名称:TradingStation,代码行数:45,代码来源:ExcelWriter.cs


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