本文整理汇总了C#中Microsoft.Office.Interop.Excel.ApplicationClass.Quit方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationClass.Quit方法的具体用法?C# ApplicationClass.Quit怎么用?C# ApplicationClass.Quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel.ApplicationClass
的用法示例。
在下文中一共展示了ApplicationClass.Quit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_detect_row_and_value_changed
public void Should_detect_row_and_value_changed()
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
string excelPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ratesource.xls");
xlWorkBook = xlApp.Workbooks.Open(excelPath, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, true, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//xlWorkSheet.Activate();
xlWorkSheet.Change += new Excel.DocEvents_ChangeEventHandler(xlWorkSheet_Change);
lock (this)
{
Monitor.Wait(this);
}
xlWorkBook.Close(false, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
示例2: Should_read_value_repeatedly
public void Should_read_value_repeatedly()
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
//xlApp.Visible = true;
//xlApp.UserControl = true;
string excelPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ratesource.xls");
xlWorkBook = xlApp.Workbooks.Open(excelPath, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, true, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//xlWorkSheet.Change += new Excel.DocEvents_ChangeEventHandler(xlWorkSheet_Change);
for (int i = 0; i < 100; i++)
{
Console.WriteLine(xlWorkSheet.get_Range("B23", "B23").Value2.ToString());
//xlWorkSheet.
Thread.Sleep(1000);
}
xlWorkBook.Close(false, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
示例3: button2_Click
private void button2_Click(object sender, EventArgs e)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
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("csharp.xls", 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("Excel file created , you can find the file c:\\csharp.net-informations.xls");
}
示例4: GetExcelSheetNames
/// <summary>
/// 获取获得当前你选择的Excel Sheet的所有名字
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string[] GetExcelSheetNames(string filePath)
{
Microsoft.Office.Interop.Excel.ApplicationClass excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
Workbooks wbs = excelApp.Workbooks;
Workbook wb = wbs.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);
int count = wb.Worksheets.Count;
string[] names = new string[count];
for (int i = 1; i <= count; i++)
{
names[i - 1] = ((Worksheet)wb.Worksheets[i]).Name;
}
wb.Close(null, null, null);
excelApp.Quit();
wbs.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wbs);
excelApp = null;
wbs = null;
wb = null;
return names;
}
示例5: btnRead_Click
// Read from the Excel workbook.
private void btnRead_Click(object sender, EventArgs e)
{
// Get the Excel application object.
Excel.Application excel_app = new Excel.ApplicationClass();
// Make Excel visible (optional).
excel_app.Visible = true;
// Open the workbook read-only.
Excel.Workbook workbook = excel_app.Workbooks.Open(txtFile.Text,
Type.Missing, true, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
// Get the first worksheet.
Excel.Worksheet sheet = (Excel.Worksheet)workbook.Sheets[1];
// Get the titles and values.
SetTitleAndListValues(sheet, 1, 1, lblTitle1, lstItems1);
SetTitleAndListValues(sheet, 1, 2, lblTitle2, lstItems2);
// Close the workbook without saving changes.
workbook.Close(false, Type.Missing, Type.Missing);
// Close the Excel server.
excel_app.Quit();
}
示例6: button3_Click
private void button3_Click(object sender, EventArgs e)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
Int16 i, j;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
for (i = 0; i <= dataGridView1.RowCount - 2; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
xlWorkSheet.Cells[i + 1, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
xlWorkBook.SaveAs(@"C:\Users\Soroush\Desktop\HospitalDatabaseOutputDrug.xls", 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);
}
示例7: Export
/// <summary>
/// this functio create a excel file with the values from a table
/// </summary>
public static string Export(string path, System.Data.DataTable dt)
{
string output = "OK";
try
{
//create a new instance of excel file
Excel.ApplicationClass excel = new Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
//first let's extract the columns and create a little header
Excel.Worksheet worksheet = (Excel.Worksheet)excel.ActiveSheet;
worksheet.get_Range(worksheet.Cells[1, 6], worksheet.Cells[65535, 6]).EntireColumn.NumberFormat = "@";
//worksheet.get_Range(worksheet.Cells[1, 6], worksheet.Cells[65535, 6]).EntireColumn.NumberFormat = "#";
worksheet.Activate();
int horizontal = 1;
int vertical = 1;
foreach (DataColumn dc in dt.Columns)
{
excel.Cells[vertical, horizontal] = dc.ColumnName;
horizontal++;
}
//go to next row
vertical++;
foreach (DataRow row in dt.Rows)
{
horizontal = 1;
foreach (DataColumn column in dt.Columns)
{
excel.Cells[vertical, horizontal] = row[column];
horizontal++;
}
vertical++;
}
//save the excel file
worksheet.Name = "PROROGHE Non Lavorate";
//DirectoryInfo dr = new DirectoryInfo(path);
//dr.Create();
FileInfo fi = new FileInfo(path);
if (fi.Exists == true)
fi.Delete();
worksheet.SaveAs(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Workbooks.Close();
excel.Quit();
}
catch (Exception ex)
{
output = ex.Message + "\n" + ex.StackTrace;
}
return output;
}
示例8: SearchByFile
public List<ResultRowCell> SearchByFile(string[] listOfWords, SupplierType supplierType, string priceFileName)
{
Application xlApp = new Excel.ApplicationClass();
xlApp.ReferenceStyle = XlReferenceStyle.xlA1;
Workbook xlWorkBook = xlApp.Workbooks.Open(priceFileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
var xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(supplierType.SheetNumber);
int lastUsedRow = xlWorkSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row;
//начало поиска
var searchResult = new List<ResultRowCell>();
for (int currentRow = supplierType.ListCell[0].Row; currentRow <= lastUsedRow; currentRow++)
{
var resultRowCell = new ResultRowCell();
resultRowCell.Clear();
for (int iCell = 0; iCell < supplierType.ListCell.Count; iCell++)
{
//для всех ячеек получаем их значения
int currentColumn = supplierType.ListCell[iCell].Col;
//проверка ячейки на существование.
var value = ((Range) xlWorkSheet.Cells[currentRow, currentColumn]).Value;
string result = "";
if (value != null)
result = value.ToString();
else
result = "";
resultRowCell.VSupplierName = supplierType.Name;
resultRowCell.Add(new ResultCell(currentRow, currentColumn, result,
supplierType.ListCell[iCell].Name));
}
//ищем по всем словам, по всем ячейкам
int qty = 0;
if ((qty = ParseRow(resultRowCell, listOfWords)) > 0)
{
//MessageBox.Show(@"Current row: " + currentRow.ToString());
resultRowCell.qty = qty;
searchResult.Add(resultRowCell);
}
}
//конец поиска
xlWorkBook.Close(false, null, null);
xlApp.Quit();
ReleaseObject(xlWorkSheet);
ReleaseObject(xlWorkBook);
ReleaseObject(xlApp);
return searchResult;
}
示例9: draw_charts
public void draw_charts()
{
Excel.Application xlApp;
Excel.Workbook xlWorkbook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkbook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1);
xlWorkSheet.Cells[1, 1] = "";
xlWorkSheet.Cells[1, 2] = "Student1";
xlWorkSheet.Cells[1, 3] = "Student2";
xlWorkSheet.Cells[1, 4] = "Student3";
xlWorkSheet.Cells[2, 1] = "Term1";
xlWorkSheet.Cells[2, 2] = "80";
xlWorkSheet.Cells[2, 3] = "65";
xlWorkSheet.Cells[2, 4] = "45";
xlWorkSheet.Cells[3, 1] = "Term2";
xlWorkSheet.Cells[3, 2] = "78";
xlWorkSheet.Cells[3, 3] = "72";
xlWorkSheet.Cells[3, 4] = "60";
xlWorkSheet.Cells[4, 1] = "Term3";
xlWorkSheet.Cells[4, 2] = "82";
xlWorkSheet.Cells[4, 3] = "80";
xlWorkSheet.Cells[4, 4] = "65";
xlWorkSheet.Cells[5, 1] = "Term4";
xlWorkSheet.Cells[5, 2] = "75";
xlWorkSheet.Cells[5, 3] = "82";
xlWorkSheet.Cells[5, 4] = "68";
Excel.Range chartRange;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250);
Excel.Chart chartPage = myChart.Chart;
chartRange = xlWorkSheet.get_Range("A1", "d5");
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = Excel.XlChartType.xlColumnClustered;
xlWorkbook.SaveAs("testgraph.xls", 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("Excel file created , you can find the file c:\\csharp.net-informations.xls");
}
示例10: writeExcel
public static bool writeExcel(System.Data.DataTable excelTable, string filePath)
{
filePath = Command.Process.root + filePath;
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.ApplicationClass();
try
{
app.Visible = false;
Workbook wBook = app.Workbooks.Add();
Worksheet wSheet = wBook.Worksheets[1] as Worksheet;
if (excelTable.Rows.Count > 0)
{
int row = 0;
row = excelTable.Rows.Count;
int col = excelTable.Columns.Count;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
string str = excelTable.Rows[i][j].ToString();
wSheet.Cells[i + 2, j + 1] = str;
}
}
}
int size = excelTable.Columns.Count;
for (int i = 0; i < size; i++)
{
wSheet.Cells[1, 1 + i] = excelTable.Columns[i].ColumnName;
}
//设置禁止弹出保存和覆盖的询问提示框
app.DisplayAlerts = false;
app.AlertBeforeOverwriting = false;
//保存工作簿
wSheet.SaveAs(filePath);
app.Quit();
//清理内存
System.Runtime.InteropServices.Marshal.ReleaseComObject(wSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wBook);
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(app) > 0) ;
wSheet = null;
wBook = null;
app = null;
GC.Collect();
return true;
}
catch (Exception err)
{
Console.WriteLine(err.Message);
return false;
}
}
示例11: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
String sFileImage = "C:\\ImgAppImages\\SAM_5022.jpg";
String sFilePath = "C:\\ImgAppImages\\sam.xls";
if (File.Exists(sFilePath)) { File.Delete(sFilePath); }
Microsoft.Office.Interop.Excel.ApplicationClass objApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Worksheet objSheet = new Microsoft.Office.Interop.Excel.Worksheet();
Microsoft.Office.Interop.Excel.Workbook objWorkBook = null;
//object missing = System.Reflection.Missing.Value;
try
{
objWorkBook = objApp.Workbooks.Add(Type.Missing);
objSheet = (Microsoft.Office.Interop.Excel.Worksheet)objWorkBook.ActiveSheet;
//Add picture to single sheet1
objSheet = (Worksheet)objWorkBook.Sheets[1];
objSheet.Name = "Graph with Report";
//////////////
//Or multiple sheets
for (int iSheet = 0; iSheet < objWorkBook.Sheets.Count - 1; iSheet++)
{
//objSheet = objWorkBook.Sheets[iSheet] as Worksheet;
///(objSheet as Microsoft.Office.Interop.Excel._Worksheet).Activate();
}
/////////////////
objSheet.Shapes.AddPicture(sFileImage, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 10, 10, 700, 350);
objWorkBook.SaveAs(sFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
catch (Exception ex)
{
//Error Alert
}
finally
{
objApp.Quit();
objWorkBook = null;
objApp = null;
}
}
示例12: CreateExcelFile
// create excel file
private void CreateExcelFile(string sName)
{
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[2, 2] = "Olap Mining Report";
xlWorkBook.SaveAs(sName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
}
示例13: Main
static void Main(string[] args)
{
var xlApp = new MSExcel.ApplicationClass();
var xlWorkbooks = xlApp.Workbooks;
xlApp.Visible = false;
xlApp.DisplayAlerts = false;
for (int i = 0; i < 500; i++)
{
var workbook = Path.Combine(Environment.CurrentDirectory, "us_foreign_assistance.xls");
//var workbook = "https://explore.data.gov/download/5gah-bvex/XLS";
var xlWorkBook = xlWorkbooks._Open(workbook, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value);
var xlWorkSheet = (MSExcel._Worksheet)xlWorkBook.Sheets["Notes"];
xlWorkSheet.Delete();
xlApp.Visible = false;
workbook = Path.Combine(Environment.CurrentDirectory, string.Format("Book-{0}.xls", i));
xlWorkBook.SaveAs(workbook, MSExcel.XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value,
false, false, MSExcel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
// Commenting this out will cause memory usage to spike.
xlWorkBook.Close(false, Missing.Value, false);
log.InfoFormat("Wrote \"{0}\".", workbook);
// Commenting this out does not seem to affect memory usage.
Marshal.ReleaseComObject(xlWorkBook);
}
xlApp.DisplayAlerts = true;
xlApp.Quit();
Marshal.ReleaseComObject(xlWorkbooks);
Marshal.ReleaseComObject(xlApp);
/*
Console.Write("Press any key to continue . . . ");
Console.ReadKey(false);
Console.WriteLine();
*/
}
示例14: CreateExcel
/// <summary>
/// 创建Excel工作薄
/// </summary>
public void CreateExcel(string path)
{
if (File.Exists(path))
{
return;
}
else
{
Excel.Application excelApp; //Excel应用程序
Excel.Workbook excelDoc; //Excel文档
excelApp = new Excel.ApplicationClass();
Object nothing = Missing.Value;
excelDoc = excelApp.Workbooks.Add(nothing);
Object format = Excel.XlFileFormat.xlWorkbookDefault;
excelDoc.SaveAs(path, nothing, nothing, nothing, nothing, nothing,
Excel.XlSaveAsAccessMode.xlExclusive, nothing, nothing, nothing, nothing, nothing);
excelDoc.Close(nothing, nothing, nothing);
excelApp.Quit();
}
}
示例15: btnCreate_Click
private void btnCreate_Click(object sender, EventArgs e)
{
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[1, 1] = "id";
xlWorkSheet.Cells[1, 2] = "name";
xlWorkBook.SaveAs("csharp.xls", 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("Excel file created , you can find the file csharp.xls");
}