本文整理汇总了C#中Microsoft.Office.Interop.Excel.Application.Quit方法的典型用法代码示例。如果您正苦于以下问题:C# Application.Quit方法的具体用法?C# Application.Quit怎么用?C# Application.Quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel.Application
的用法示例。
在下文中一共展示了Application.Quit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpotToExcel
public void ExpotToExcel(DataGridView dataGridView1,string SaveFilePath)
{
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
}
}
xlWorkBook.SaveAs(SaveFilePath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show("Your file is saved" + SaveFilePath);
}
示例2: GetDataFromExcel
/// <exception cref="FileNotFoundException"><c>FileNotFoundException</c>.</exception>
/// <exception cref="Exception"><c>Exception</c>.</exception>
public IList<IDataRecord> GetDataFromExcel(string filePath)
{
try
{
Log.Info("Начало импорта");
if (!File.Exists(filePath))
throw new FileNotFoundException(string.Format("Файл не найден. [{0}]", filePath));
Excelapp = new Application { Visible = false };
Workbook = Excelapp.Workbooks.Open(filePath, 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);
ReadDoc();
}
catch( Exception e)
{
Log.Error("Ошибка импорта", e);
throw;
}
finally
{
Workbook.Close();
Excelapp.Quit();
Excelapp = null;
}
return DataRecords;
}
示例3: ExportToExcel
static void ExportToExcel(List<Car> carsInStock)
{
// Load up Excel, then make a new empty workbook.
Excel.Application excelApp = new Excel.Application();
excelApp.Workbooks.Add();
// This example uses a single workSheet.
Excel._Worksheet workSheet = excelApp.ActiveSheet;
// Establish column headings in cells.
workSheet.Cells[1, "A"] = "Make";
workSheet.Cells[1, "B"] = "Color";
workSheet.Cells[1, "C"] = "Pet Name";
// Now, map all data in List<Car> to the cells of the spread sheet.
int row = 1;
foreach (Car c in carsInStock)
{
row++;
workSheet.Cells[row, "A"] = c.Make;
workSheet.Cells[row, "B"] = c.Color;
workSheet.Cells[row, "C"] = c.PetName;
}
// Give our table data a nice look and feel.
workSheet.Range["A1"].AutoFormat(
Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2);
// Save the file, quit Excel and display message to user.
workSheet.SaveAs(string.Format(@"{0}\Inventory.xlsx", Environment.CurrentDirectory));
excelApp.Quit();
MessageBox.Show("The Inventory.xslx file has been saved to your app folder", "Export complete!");
}
示例4: Convert
public static new Boolean Convert(String inputFile, String outputFile) {
Microsoft.Office.Interop.Excel.Application app;
String tmpFile = null;
object oMissing = System.Reflection.Missing.Value;
try {
app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = true;
Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
Microsoft.Office.Interop.Excel.Workbook workbook = null;
workbooks = app.Workbooks;
workbook = workbooks.Open(inputFile, true, true, oMissing, oMissing, oMissing, true, oMissing, oMissing, oMissing, oMissing, oMissing, false, oMissing, oMissing);
// Try and avoid xls files raising a dialog
tmpFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".xls" + (workbook.HasVBProject ? "m" : "x");
workbook.SaveAs(tmpFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing);
workbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
outputFile, Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard, Type.Missing, false, Type.Missing, Type.Missing, false, Type.Missing);
workbooks.Close();
app.Quit();
return true;
} catch (Exception e) {
Console.WriteLine(e.Message);
return false;
} finally {
if (tmpFile != null) {
System.IO.File.Delete(tmpFile);
}
app = null;
}
}
示例5: exportTable
public bool exportTable()
{
try
{
//Подготовка
excel= new InteropExcel.ApplicationClass ();
if (excel==null) return false;
excel.Visible=false;
InteropExcel.Workbook workbook=excel.Workbooks.Add();
if(workbook==null) return false;
InteropExcel.Worksheet sheet=(InteropExcel.worksheet) workbook.worksheets[1]
sheet.Name="Таблица1"
//Попълване на таблицата
//Запаметяване и затваряне
workbook.SaveCopyAs(getPath());
excel.DisplayAlerts=false; //изключване на всички съобщения на Excel
workbook.Close();
excel.Quit ();
return true;
}catch{
}
return false;
}
示例6: OldWay
//C# 4.0 미만에서 COM컴포넌트 사용하는 코드
public static void OldWay(string[,] data, string savePath)
{
Excel.Application excelApp = new Excel.Application();
//의미없는 매개변수 입력
excelApp.Workbooks.Add(Type.Missing);
//형변환
Excel.Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet;
for (int i = 0; i < data.GetLength(0); i++)
{
//형변환
((Excel.Range)workSheet.Cells[i + 1, 1]).Value2 = data[i, 0];
((Excel.Range)workSheet.Cells[i + 1, 2]).Value2 = data[i, 1];
}
//의미없는 매개변수 입력
workSheet.SaveAs(savePath + "\\addressbook-old.xlsx",
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);
excelApp.Quit();
}
示例7: CreateExcel
// Create a method that is called when the testExcel button is pushed
private void CreateExcel(object sender, EventArgs e)
{
Excel.Application excel = new Excel.Application();
excel.Visible = false;
excel.DisplayAlerts = false;
Excel.Workbook wb = excel.Workbooks.Add();
Excel.Worksheet sh = wb.Sheets.Add();
sh.Name = "JPMorgan";
sh.Cells[1, "A"].Value = "Vendor Name";
sh.Cells[1, "B"].Value = "City";
sh.Cells[1, "C"].Value = "Zip Code";
sh.Cells[1, "D"].Value = "Tax ID";
sh.Cells[1, "E"].Value = "Phone";
sh.Cells[1, "F"].Value = "Email";
sh.Cells[1, "G"].Value = "Currency ID";
sh.Cells[2, "A"].Value = this.pmTrxForm.PmVendorMaintenance.VendorName.Value;
sh.Cells[2, "B"].Value = this.pmTrxForm.PmVendorMaintenance.City.Value;
sh.Cells[2, "C"].Value = this.pmTrxForm.PmVendorMaintenance.ZipCode.Value;
sh.Cells[2, "D"].Value = this.pmTrxForm.PmVendorMaintenanceAdditionalInformation.TaxIdNumber.Value;
sh.Cells[2, "E"].Value = this.pmTrxForm.PmVendorMaintenance.PhoneNumber1.Value;
sh.Cells[2, "F"].Value = this.pmTrxForm.PmVendorMaintenance.Comment1.Value;
sh.Cells[2, "G"].Value = this.pmTrxForm.PmVendorMaintenanceAdditionalInformation.CurrencyId.Value;
wb.SaveAs(@"D:\Excel\testdata.xlsx");
wb.Close(true);
excel.Quit();
}
示例8: CallMacro
public void CallMacro(string file)
{
Excel.Application xlApp;
Workbook xlWorkBook;
Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(file);//, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet
MessageBox.Show(xlWorkSheet.get_Range("A1", "A1").Value2.ToString());
RunMacro(
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
// Application.Run "PERSONAL.XLSB!CleanDocket"
//Application.Run "PERSONAL.XLSB!Create_Upcoming_Docket"
//Sheets("Upcoming Hearings").Select
//Sheets("Upcoming Hearings").Move Before:=Sheets(1)
/*
*
*
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);*/
}
示例9: ProcessRequest
public void ProcessRequest(HttpContext context)
{
//' This line is very important!
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-EN");//<-- change culture on whatever you need
Excel.Application xlAppoutput = null;
Excel.Workbook xlWorkBookoutput = null;
Excel.Worksheet xlWorkSheetoutput = null;
Excel.Range rangeoutput = null;
object missing = Type.Missing;
try
{
xlAppoutput = new Excel.Application();
xlWorkBookoutput =xlAppoutput.Workbooks.Open("D:\\DevBusra\\Projects\\ExportExcel\\ExportExcel\\BaseFiles\\ExcelForm.xlsx");
Excel.Worksheet xlWorkSheetToEdit = default(Excel.Worksheet);
//xlWorkBookoutput = xlAppoutput.Workbooks.Open();
//xlAppoutput = new Excel.ApplicationClass();
//xlWorkBookoutput = xlAppoutput.Workbooks.Open(@"D:\DevBusra\Projects\ExportExcel\ExportExcel\BaseFiles\ExcelForm.xlsx");
//xlWorkBookoutput = xlAppoutput.Workbooks.Open(@"C:\UsedFiles\points.xls", missing, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
xlWorkSheetoutput = xlAppoutput.Worksheets.get_Item(1);
rangeoutput = xlWorkSheetoutput.UsedRange;
(rangeoutput.Cells[1,5] as Excel.Range).Value2 = "Saat";
(rangeoutput.Cells[2,5] as Excel.Range).Value2 = DateTime.Now.ToShortTimeString();
((Excel._Workbook)xlWorkBookoutput).Close(true, missing, missing);
xlAppoutput.Quit();
}
catch (Exception ex)
{
System.Console.Write(ex.StackTrace);
}
finally
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlAppoutput);
}
}
示例10: read
public void read(string path, ref List<string> name, ref List<string> phone, ref List<string> email,ref List<string> gname)
{
createfile objcf = new createfile();
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
object missing = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(path, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, true, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
string str,str1,str2,str3;
for (int rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
str = (string)(range.Cells[rCnt, 1] as Excel.Range).Value2;
str1 = (string)((range.Cells[rCnt, 2] as Excel.Range).Value2).ToString();
str2 = (string)(range.Cells[rCnt, 3] as Excel.Range).Value2;
str3 = (string)(range.Cells[rCnt, 5] as Excel.Range).Value2;
name.Add(str);
phone.Add(str1);
email.Add(str2);
gname.Add(str3);
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
objcf.releaseObject(xlWorkSheet);
objcf.releaseObject(xlWorkBook);
objcf.releaseObject(xlApp);
}
示例11: SavePdf
/// <summary>
/// ファイルをPDF形式で保存
/// </summary>
public override void SavePdf()
{
Microsoft.Office.Interop.Excel.Application app = null;
Microsoft.Office.Interop.Excel.Workbooks books = null;
Microsoft.Office.Interop.Excel.Workbook book = null;
try
{
app = new Microsoft.Office.Interop.Excel.Application();
books = app.Workbooks;
book = books.Open(this.GetAbsolutePath());
book.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, this.GetPdfPath(), XlFixedFormatQuality.xlQualityStandard);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
finally
{
if (book != null)
{
book.Close();
}
if (app != null)
{
app.Quit();
}
}
}
示例12: SaveDataInExcel
public void SaveDataInExcel(IScriptWorker CurrentScriptWorker, string SavePath)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlApp.Visible = true;
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int RowCounter, ColumnCounterForNamesOfTests;
WriteDataToWorkSheet(CurrentScriptWorker, xlWorkSheet, out RowCounter, out ColumnCounterForNamesOfTests);
CreateGraph(CurrentScriptWorker, xlWorkSheet, RowCounter, ColumnCounterForNamesOfTests);
if (SavePath == null || SavePath == string.Empty)
{
SavePath = Directory.GetCurrentDirectory() + MyResources.Texts.DefaultFileName;
}
xlWorkBook.SaveAs(SavePath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show(MyResources.Texts.ExcelFileWasCreatedMessage + SavePath);
}
示例13: GetPPEFormExcel
static void GetPPEFormExcel()
{
Console.WriteLine("please choose Excel File");
OpenFileDialog ofD = new OpenFileDialog(); ofD.ShowDialog();
string fName = ofD.FileName;
Excel.Application xApp = new Excel.Application();
xApp.Visible = true;
Excel.Workbook xbook = xApp.Workbooks.Open(fName);
Excel.Worksheet xSheet = xbook.Sheets[1];
xSheet.Select();
Excel.Range xRange = null;
string appName = null; string ie = null; string firefox = null; string chrome = null;
int i = 2;
xRange = xSheet.Cells[i,1]; appName = xRange.Value2;
while (!String.IsNullOrEmpty(appName))
{
nameArr.Add(GetAppKey(appName));
xRange = xSheet.Cells[i, 4]; ie = xRange.Value2; ieArr.Add(ie);
xRange = xSheet.Cells[i, 5]; firefox = xRange.Value2; firefoxArr.Add(firefox);
xRange = xSheet.Cells[i, 6]; chrome = xRange.Value2; chromeArr.Add(chrome);
//Console.WriteLine("Name:{0} IE:{1} FireFox:{2} Chrome:{3}", appName,ie,firefox,chrome);
i++;
xRange = xSheet.Cells[i, 1]; appName = xRange.Value2;
}
Console.WriteLine("Done");
xSheet = null; xbook = null; xApp.Quit();xApp = null;
}
示例14: ReadProcesses
public void ReadProcesses()
{
count = 0;
ExcelApp = new Excel.Application();
ExcelApp.Visible = false;
WorkBookExcel = ExcelApp.Workbooks.Open(_filePath, false); //открываем книгу
//Читаем данные по проектам
WorkSheetExcel = (Excel.Worksheet)WorkBookExcel.Sheets["Processes"]; //Получаем ссылку на лист Processes
List<string> row = new List<string>();
int n = 6;
for (int i = 2; WorkSheetExcel.Cells[i, 1].Text.ToString() != ""; i++)
{
row = new List<string>();
for (int j = 1; j < n; j++) row.Add(WorkSheetExcel.Cells[i, j].Text.ToString()); //строка массива заполняется просто суммой i и j
Mas.Add(row); //строка добавляется в массив
count++;
}
//test = WorkSheetExcel.Cells[2, 1];
WorkBookExcel.Close(false, Type.Missing, Type.Missing);
ExcelApp.Quit();
GC.Collect();
}
示例15: Write
public bool Write(Dictionary<Guid,string> source, Adam.Core.Application app)
{
Record r = new Record(app);
Excel.Application EApp;
Excel.Workbook EWorkbook;
Excel.Worksheet EWorksheet;
Excel.Range Rng;
EApp = new Excel.Application();
object misValue = System.Reflection.Missing.Value;
EWorkbook = EApp.Workbooks.Add(misValue);
EWorksheet = (Excel.Worksheet)EWorkbook.Worksheets.Item[1];
EWorksheet.get_Range("A1", misValue).Formula = "UPC code";
EWorksheet.get_Range("B1", misValue).Formula = "Link";
Rng = EWorksheet.get_Range("A2", misValue).get_Resize(source.Count,misValue);
Rng.NumberFormat = "00000000000000";
int row = 2;
foreach(KeyValuePair<Guid,string> pair in source)
{
EWorksheet.Cells[row,1] = pair.Value;
r.Load(pair.Key);
Rng = EWorksheet.get_Range("B"+row, misValue);
EWorksheet.Hyperlinks.Add(Rng, r.Fields.GetField<TextField>("Content Url").Value);
//myExcelWorksheet.Cells[row, 2] = r.Fields.GetField<TextField>("Content Url").Value;
row++;
}
((Excel.Range)EWorksheet.Cells[2, 1]).EntireColumn.AutoFit();
((Excel.Range)EWorksheet.Cells[2, 2]).EntireColumn.AutoFit();
EWorkbook.SaveAs(_fileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue,
Excel.XlSaveAsAccessMode.xlExclusive,
misValue, misValue, misValue, misValue, misValue);
EWorkbook.Close(true, misValue, misValue);
EApp.Quit();
return true;
}