本文整理汇总了C#中ApplicationClass.Quit方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationClass.Quit方法的具体用法?C# ApplicationClass.Quit怎么用?C# ApplicationClass.Quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationClass
的用法示例。
在下文中一共展示了ApplicationClass.Quit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
private static Worksheet mySheet1; //工作簿1
#endregion Fields
#region Methods
public static List<List<string>> Read(string fileName,int columnCount,int startRowIndex)
{
List<List<string>> textList = new List<List<string>>();
excelApp = new ApplicationClass();
Workbooks myWorkBooks = excelApp.Workbooks;
myWorkBooks.Open(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Sheets sheets = excelApp.Sheets;
mySheet1 = (Worksheet)sheets[1];
int rowCount = mySheet1.UsedRange.Rows.Count;
if (rowCount != 0)
{
for (int i = startRowIndex; i <= rowCount; i++)
{
string name = ((Range)mySheet1.Cells[i, 2]).Text.ToString();
if (name != "") {
List<string> list = new List<string>();
list.Add((i-startRowIndex+1).ToString());
for (int j = 0; j < columnCount; j++)
{
list.Add(((Range)mySheet1.Cells[i, j + 1]).Text.ToString());
}
textList.Add(list);
}
}
}
myWorkBooks.Close();
excelApp.Quit();
excelApp = null;
return textList;
}
示例2: EncryptExcelByPassword
/// <summary>
///
/// </summary>
/// <param name="UnEncryptFileName">Excel原始檔名</param>
/// <param name="EncryptFileName">Excel加密後檔名</param>
/// <param name="OpenExcelPassword">允許開啟密碼</param>
/// <param name="WriteExcelPassword">允許編寫密碼</param>
public static void EncryptExcelByPassword(string UnEncryptFileName, string EncryptFileName,
string OpenExcelPassword, string WriteExcelPassword)
{
ApplicationClass xApp = new ApplicationClass();
try
{
Workbook xBook = xApp.Workbooks.Open(UnEncryptFileName,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
if (File.Exists(EncryptFileName)) File.Delete(EncryptFileName);
xBook.SaveAs(EncryptFileName, XlFileFormat.xlExcel12
, OpenExcelPassword, WriteExcelPassword, Missing.Value,
Missing.Value, XlSaveAsAccessMode.xlNoChange, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xBook.Save();
xBook.Close();
xBook = null;
}
catch (Exception ex)
{
throw ex;
}
finally
{
xApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xApp);
xApp = null;
}
GC.Collect();
}
示例3: ConvertDocument
void ConvertDocument(Guid g, string fileName)
{
object m = System.Reflection.Missing.Value;
object oldFileName = (object)fileName;
object readOnly = (object)false;
ApplicationClass ac = null;
try
{
// First, create a new Microsoft.Office.Interop.Word.ApplicationClass.
ac = new ApplicationClass();
// Now we open the document.
Document doc = ac.Documents.Open(ref oldFileName, ref m, ref readOnly,
ref m, ref m, ref m, ref m, ref m, ref m, ref m,
ref m, ref m, ref m, ref m, ref m, ref m);
// Create a temp file to save the HTML file to.
string tempFileName =Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + g.ToString() + ".html";
// Cast these items to object. The methods we're calling
// only take object types in their method parameters.
object newFileName = (object)tempFileName;
// We will be saving this file as HTML format.
object fileType = (object)WdSaveFormat.wdFormatHTML;
// Save the file.
doc.SaveAs(ref newFileName, ref fileType,
ref m, ref m, ref m, ref m, ref m, ref m, ref m,
ref m, ref m, ref m, ref m, ref m, ref m, ref m);
}
finally
{
// Make sure we close the application class.
if (ac != null)
ac.Quit(ref readOnly, ref m, ref m);
}
}
示例4: Bai2_Load
private void Bai2_Load(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new ApplicationClass();
object o_nullobject = System.Reflection.Missing.Value;
object o_filePath = System.IO.Directory.GetCurrentDirectory() + "\\Resources\\PhepNhan.doc";
object o_format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object o_endings = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
object o_Readonly = true;
Microsoft.Office.Interop.Word.Document doc = wordApplication.Documents.Open(ref o_filePath,
ref o_nullobject, ref o_Readonly, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
txtLyThuyet.Text = data.GetData(DataFormats.UnicodeText).ToString();
doc.Close(ref o_nullobject, ref o_nullobject, ref o_nullobject);
wordApplication.Quit(ref o_nullobject, ref o_nullobject, ref o_nullobject);
PhepTinhDAO phepTinhDAO = new PhepTinhDAO();
PhepTinhDTO phepTinhDTO = new PhepTinhDTO();
arrPhepTinh = phepTinhDAO.getPhepTinhNhan();
sizeOfXML = arrPhepTinh.Count;
phepTinhDTO = (PhepTinhDTO)arrPhepTinh[0];
tbTemp1.Text = phepTinhDTO.SoThuNhat.ToString();
tbTemp2.Text = phepTinhDTO.SoThuHai.ToString();
}
示例5: Bai1_Load
private void Bai1_Load(object sender, EventArgs e)
{
currentIndex=0;
So5ChuSoDAO so5ChuSoDAO = new So5ChuSoDAO();
So5ChuSoDTO so5ChuSoDTO = null;
arrSo5ChuSo = so5ChuSoDAO.getSo5ChuSo();
sizeOfXML = arrSo5ChuSo.Count;
so5ChuSoDTO = (So5ChuSoDTO)arrSo5ChuSo[0];
lbDocSo.Text = so5ChuSoDTO.Text;
currentResult = so5ChuSoDTO.Number;
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new ApplicationClass();
object o_nullobject = System.Reflection.Missing.Value;
object o_filePath = System.IO.Directory.GetCurrentDirectory() + "\\Resources\\CacSoCo5ChuSo.doc";
object o_format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object o_endings = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
object o_Readonly = true;
Microsoft.Office.Interop.Word.Document doc = wordApplication.Documents.Open(ref o_filePath,
ref o_nullobject, ref o_Readonly, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
txtLyThuyet.Text = data.GetData(DataFormats.UnicodeText).ToString();
doc.Close(ref o_nullobject, ref o_nullobject, ref o_nullobject);
wordApplication.Quit(ref o_nullobject, ref o_nullobject, ref o_nullobject);
}
示例6: ConvertDocument
void ConvertDocument(Guid g, string fileName)
{
object m = System.Reflection.Missing.Value;
object oldFileName = (object)fileName;
object readOnly = (object)false;
ApplicationClass ac = null;
System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
try
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
// First, create a new Microsoft.Office.Interop.Word.ApplicationClass.
ac = new ApplicationClass();
// Now we open the document.
Presentation doc = ac.Presentations.Open(fileName , Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
// Create a temp file to save the HTML file to.
string tempFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), g.ToString() + ".html");
// Cast these items to object. The methods we're calling
// only take object types in their method parameters.
// Save the file.
doc.SaveAs(tempFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoFalse);
}
finally
{
// Make sure we close the application class.
if (ac != null)
ac.Quit();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
}
}
示例7: GetSheetNames
public static List<string> GetSheetNames(string fileName)
{
ApplicationClass excelapp = new ApplicationClass();
RecentFile re = excelapp.RecentFiles.Add(fileName);// nhan ve file vua chon de xu ly
List<string> lstSheet = new List<string>();
try
{
excelapp.Visible = false;
Workbook excelWorkbook = re.Open();// mở ra và có thể truy xuất các sheet
if (excelWorkbook.Sheets.Count > 0)
{
Worksheet excelWorkSheet;
for (int i = 1; i <= excelWorkbook.Sheets.Count; i++)
{
excelWorkSheet = (Worksheet)excelWorkbook.Sheets[i];
lstSheet.Add(excelWorkSheet.Name);
}
excelWorkSheet = null;
}
excelWorkbook = null;
re.Application.Quit();
excelapp.Quit();// thoat khoi chuong trinh excel.exe trong he thong
}
catch (Exception) { }
return lstSheet;
}
示例8: SaveExcelFile
public static void SaveExcelFile(string fileName, string tempFileName,string[,] contents, int startColumn, int startRow)
{
try
{
excelApp = new ApplicationClass();
Workbooks myWorkBooks = excelApp.Workbooks;
myWorkBooks.Open(tempFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Sheets sheets = excelApp.Sheets;
mySheet1 = (Worksheet)sheets[1];
mySheet1.Activate();
//写入测试信息
Range range1 = mySheet1.get_Range(mySheet1.Cells[startRow, startColumn], mySheet1.Cells[contents.GetLength(0)+startRow-1,contents.GetLength(1)+startColumn-1]);
range1.Value2 = contents;
mySheet1.SaveAs(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing);
myWorkBooks.Close();
excelApp.Quit();
excelApp = null;
}
catch (Exception ee)
{
throw ee;
}
}
示例9: Convert
public int Convert(string sourcePath, string targetPath)
{
if (!File.Exists(sourcePath))
{
return ErrorMessages.FileNotExist;
}
XlFixedFormatType targetType = XlFixedFormatType.xlTypePDF;
object missing = Type.Missing;
ApplicationClass application = new ApplicationClass(); ;
Workbook workBook = null;
try
{
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
//设置格式,导出成PDF
Worksheet sheet = (Worksheet)workBook.Worksheets[1]; //下载从1开始
//把sheet设置成横向
sheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
//可以设置sheet页的其他相关设置,不列举
sheet.ExportAsFixedFormat(targetType,
targetPath,
XlFixedFormatQuality.xlQualityStandard,
true,
false,
missing,
missing,
missing,
missing);
return ErrorMessages.ConvertSuccess;
}
catch (COMException ex)
{
_logger.Error(ex.StackTrace);
_logger.Error(ex.Message);
return ErrorMessages.OfficeToPdfUninstall;
}
catch (Exception ex)
{
_logger.Error(ex.Message);
return ErrorMessages.ConvertFailed;
}
finally
{
if (workBook != null)
{
workBook.Close(true, missing, missing);
}
if (application != null)
{
application.Quit();
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
示例10: ExcelFromDataTable
public static void ExcelFromDataTable(System.Data.DataTable dt, string file)
{
// Create an Excel object and add workbook...
ApplicationClass excel = new ApplicationClass();
Workbook workbook = excel.Application.Workbooks.Add(Type.Missing);
var worksheets = workbook.Sheets;
var worksheet = (Worksheet)worksheets[1];
// Add column headings...
int iCol = 0;
foreach (DataColumn c in dt.Columns)
{
iCol++;
excel.Cells[1, iCol] = c.ColumnName.Trim();
}
WriteNumberFormatByColumn(dt.Rows.Count + 1, dt.Columns.Count + 1, worksheet);
WriteArray(dt.Rows.Count, dt.Columns.Count, worksheet, dt.Rows);
//// for each row of data...
//int iRow = 0;
//foreach (DataRow r in dt.Rows)
//{
// iRow++;
// // add each row's cell data...
// iCol = 0;
// foreach (DataColumn c in dt.Columns)
// {
// iCol++;
// // data type format is Text
// ((Range)excel.Cells[iRow + 1, iCol]).NumberFormat = "@";
// excel.Cells[iRow + 1, iCol] = r[c.ColumnName].ToString().Trim();
// }
//}
// Global missing reference for objects we are not defining...
object missing = System.Reflection.Missing.Value;
//remove file
//File.Delete(file);
excel.DisplayAlerts = false;
workbook.SaveAs(file,
XlFileFormat.xlWorkbookNormal, missing, missing,
false, false, XlSaveAsAccessMode.xlShared,
false, false, missing, missing, missing);
workbook.Close(false, missing, missing);
excel.Quit();
releaseObject(workbook);
releaseObject(worksheets);
releaseObject(excel);
}
示例11: PPT2RTDwithSVG
public static RTDocument PPT2RTDwithSVG(string pptFilename)
{
//Pri2: Investigate where BasePath is and where we should be putting it in more depth.
// Concerned that we're creating directories there that never get cleaned up...
if (!Directory.Exists(tfc.BasePath))
Directory.CreateDirectory(tfc.BasePath);
// Initialize PowerPoint app
ApplicationClass ppt = new ApplicationClass();
ppt.Visible = MsoTriState.msoTrue;
// Open the PPT file
Presentation presentation = ppt.Presentations.Open(pptFilename, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
PrintOptions po = presentation.PrintOptions;
po.ActivePrinter = @"SVGmaker";
System.Threading.Thread.Sleep(6000);
po.OutputType = PpPrintOutputType.ppPrintOutputSlides;
po.PrintInBackground = MsoTriState.msoFalse;
Slides slides = presentation.Slides;
// Set up the document
RTDocument rtDoc = new RTDocument();
rtDoc.Identifier = Guid.NewGuid();
rtDoc.Metadata.Title = GetPresentationProperty(ppt.ActivePresentation, "Title");
rtDoc.Metadata.Creator = GetPresentationProperty(ppt.ActivePresentation, "Author");
//Iterate through the pages
foreach(Slide s in slides)
{
// Set the page properties
Page p = new Page();
p.Identifier = Guid.NewGuid();
p.Extension = GetSlideSVG(presentation, s);
p.MimeType = "image/svg"; // TODO: look up the real value for this
rtDoc.Resources.Pages.Add(p.Identifier, p);
// Set the TOCNode properties for the page
TOCNode tn = new TOCNode();
tn.Title = GetSlideTitle(s);
tn.Resource = p;
tn.ResourceIdentifier = p.Identifier;
// TODO: Insert thumbnail? (tn.thumbnail)
rtDoc.Organization.TableOfContents.Add(tn);
}
// Close PPT
presentation.Close();
if (ppt.Presentations.Count == 0)
{
ppt.Quit();
}
ppt = null;
tfc.Delete();
return rtDoc;
}
示例12: ExportToExcel
public static void ExportToExcel(IDataTable<DataRow> data, string filename,Protocol.Structure.WaitObject wt)
{
if (data == null)
return;
var excel = new ApplicationClass();
if (excel == null)
throw new Exception("Excel无法启动");
int rowNum = data.RowCount;
string[] columns = data.GetColumnsList();
int columnNum = columns.Length;
wt.Flags = new int[1];
wt.Max = rowNum * columnNum;
int rowIndex = 1;
int columnIndex = 0;
var book = excel.Application.Workbooks.Add(true);
try
{
foreach (var column in columns)
{
columnIndex++;
excel.Cells[rowIndex, columnIndex] = column;
if (data.GetColumnType(column) == typeof(string))
excel.get_Range(excel.Cells[rowIndex + 1, columnIndex], excel.Cells[rowNum + 1, columnIndex]).NumberFormatLocal = "@";
}
for (int i = 0; i < rowNum; i++)
{
rowIndex++;
columnIndex = 0;
for (int j = 0; j < columnNum; j++)
{
columnIndex++;
excel.Cells[rowIndex, columnIndex] = data[i,columns[j]];
wt.Flags[0]++;
}
}
excel.DisplayAlerts = false;
excel.AlertBeforeOverwriting = false;
book.SaveCopyAs(filename);
}
catch (Exception ex)
{
throw ex;
}
finally
{
book.Close(false);
book = null;
excel.Quit();
excel = null;
}
}
示例13: bt_CreateXLSFile_Click
protected void bt_CreateXLSFile_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;
ApplicationClass ExcelApp = new ApplicationClass();
try
{
Workbook workbook1 = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet worksheet1 = (Worksheet)workbook1.Worksheets["sheet1"];
worksheet1.Name = "AAA";
try
{
worksheet1.Cells[1, 1] = "姓名";
worksheet1.Cells[1, 2] = "性别";
worksheet1.Cells[1, 3] = "生日";
worksheet1.Cells[2, 1] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
worksheet1.Cells[2, 2] = "=1+1";
ExcelApp.DisplayAlerts = false;
ExcelApp.AlertBeforeOverwriting = false;
workbook1.SaveAs("D:\\" + tbx_FileName.Text, XlFileFormat.xlExcel8, "", "", false, false, XlSaveAsAccessMode.xlNoChange, 1, false, missing, missing, missing);
}
catch { }
finally
{
workbook1.Close(false, missing, missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet1);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook1);
worksheet1 = null;
workbook1 = null;
}
}
catch { }
finally
{
ExcelApp.Workbooks.Close();
ExcelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelApp);
ExcelApp = null;
GC.Collect();
//GC.WaitForPendingFinalizers();
}
}
示例14: Convert
public int Convert(string sourcePath, string targetPath)
{
if (!File.Exists(sourcePath))
{
return ErrorMessages.FileNotExist;
}
ApplicationClass application = null;
Presentation presentation = null;
try
{
application = new ApplicationClass();
presentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse,
MsoTriState.msoFalse);
presentation.SaveAs(targetPath, PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);
return ErrorMessages.ConvertSuccess;
}
catch (COMException ex)
{
_logger.Error(ex.StackTrace);
_logger.Error(ex.Message);
return ErrorMessages.OfficeToPdfUninstall;
}
catch (Exception ex)
{
_logger.Error(ex.Message);
return ErrorMessages.ConvertFailed;
}
finally
{
if (presentation != null)
{
presentation.Close();
}
if (application != null)
{
application.Quit();
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
示例15: Main
static void Main(string[] args)
{
if (args.Length == 0) {
PrintHelp();
return;
}
if (!File.Exists(args[0])) {
Console.WriteLine(args[0] + " file does not exist");
PrintHelp();
return;
}
var arguments = ReadArgs(args);
Microsoft.Office.Interop.Word.ApplicationClass wordObject = new ApplicationClass();
object filename = Path.GetTempFileName();
try {
object file = Path.GetFullPath(arguments["in"]);
object nullobject = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document docs = wordObject.Documents.Open
(ref file, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject);
try {
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDOSText;
object encoding = ReadEncoding(arguments["enc"]);
docs.SaveAs(ref filename, ref format, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref encoding, ref nullobject, ref nullobject, ref nullobject, ref nullobject);
} finally {
docs.Close();
}
} finally {
wordObject.Quit();
}
Console.Write(File.ReadAllText(filename.ToString()));
if (arguments["out"] != null)
File.Copy(filename.ToString(), args[1], true);
File.Delete(filename.ToString());
}