本文整理汇总了C#中Microsoft.Office.Interop.Excel.Workbook.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.Close方法的具体用法?C# Workbook.Close怎么用?C# Workbook.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel.Workbook
的用法示例。
在下文中一共展示了Workbook.Close方法的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: readData
public getData readData()
{
getData.dateT.Clear();
getData.prj.Clear();
getData.descr.Clear();
getData.taskTime.Clear();
notes.Clear();
ExcelApp = new Excel.Application();
ExcelApp.Visible = false;
WorkBookExcel = ExcelApp.Workbooks.Open(_filePath, false); //открываем книгу
WorkSheetExcel = (Excel.Worksheet)WorkBookExcel.Sheets[1]; //Получаем ссылку на лист 1
//excelcells = excelworksheet.get_Range("D215", Type.Missing); //Выбираем ячейку для вывода A1
// WorkSheetExcel.Cells[i, 1].Text.ToString() != ""
for (int i = 2; WorkSheetExcel.Cells[i, 1].Text.ToString() != ""; i++)
{
getData.dateT.Add(WorkSheetExcel.Cells[i, 1].Text.ToString());
getData.prj.Add(WorkSheetExcel.Cells[i, 2].Text.ToString());
getData.descr.Add(WorkSheetExcel.Cells[i, 3].Text.ToString());
getData.taskTime.Add(WorkSheetExcel.Cells[i, 4].Text.ToString());
}
WorkBookExcel.Close(false, Type.Missing, Type.Missing); //закрыл не сохраняя
ExcelApp.Quit();
GC.Collect();
getData.dateT.Reverse();
getData.prj.Reverse();
getData.descr.Reverse();
getData.taskTime.Reverse();
return getData;
}
示例3: 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();
}
示例4: 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;
}
示例5: EditWorkFlow
private Worksheet objExcelWorkSheet; //定义Workbook工作表对象
#endregion Fields
#region Methods
// Change the Mapping WorkFlow @2015-7-16 By CC
public void EditWorkFlow(string StrTestData)
{
objExcelApp = new Microsoft.Office.Interop.Excel.Application();
objExcelWorkBooks = objExcelApp.Workbooks;
objExcelWorkbook = objExcelWorkBooks.Open(StrTestData, 0, false, 5, "", "", true,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
objExcelWorkSheet = (Worksheet)objExcelWorkbook.Worksheets["WorkFlow"]; //strSheetName is the Sheet Name of Exce,if there is no name then Defult is "1"
objExcelWorkSheet.Select(Type.Missing);
int rowsint = objExcelWorkSheet.UsedRange.Cells.Rows.Count; //get the Row Number
int columnsint = objExcelWorkSheet.UsedRange.Cells.Columns.Count;//get the column number
int rowNo = 0;
int ParameterRowNo = 0;
int columnNo = 0;
int FlagColumnNo = 0;
for (int j = 1; j <= columnsint; j++)
{
string strColumnsName = ((Range)objExcelWorkSheet.Cells[1, j]).Text.ToString();
if (strColumnsName == "Flag")
{
FlagColumnNo = j;
}
if (strColumnsName == "BusinessFlow")
{
rowNo = j;
}
if (strColumnsName == "ParameterValue")
{
ParameterRowNo = j;
}
}
for (int i = 2; i <= rowsint; i++)
{
string strFlagValue = ((Range)objExcelWorkSheet.Cells[i, FlagColumnNo]).Text.ToString();
if (strFlagValue =="Y")
{
int RowNO = i;
objExcelWorkSheet.Cells[RowNO, FlagColumnNo] = "N";
}
string strBusinessFlow = ((Range)objExcelWorkSheet.Cells[i, rowNo]).Text.ToString();
if (strBusinessFlow == "HeaderMapping" || strBusinessFlow == "TaxMapping" || strBusinessFlow == "LineItemsMapping")
{
columnNo = i;
string strParameterValue = ((Range)objExcelWorkSheet.Cells[i, ParameterRowNo]).Text.ToString();
if (strParameterValue == "IR" || strParameterValue == "TradeBilling" || strParameterValue == "TradeCredit" || strParameterValue == "TradeDebit" || strParameterValue == "TradeReturn")
{
objExcelWorkSheet.Cells[i, 1] = "Y";
}
}
}
objExcelWorkbook.Save();
objExcelWorkbook.Close(false, StrTestData, false);
objExcelApp.Quit();
NAR(objExcelApp);
NAR(objExcelWorkbook);
NAR(objExcelWorkSheet);
}
示例6: button1_Click
private void button1_Click(object sender, EventArgs e)
{
var filepath = @"d:\dupa.xlsx";
MyApp = new Excel.Application();
MyApp.Visible = false;
MyBook = MyApp.Workbooks.Open(filepath);
MySheet = (Excel.Worksheet)MyBook.Sheets["Arkusz3"]; // Explicit cast is not required here
Excel.Range cell = MySheet.Range[MySheet.Cells[1, 1], MySheet.Cells[4, 4]];
foreach (Excel.Range item in cell)
{
item.Value = string.Format("row:{0:D2} col:{1:D2}", item.Row, item.Column);
}
MyBook.SaveAs(Filename: filepath);
MyBook.Close();
}
示例7: WriteInExl
//public Write2Exl()
//{
//}
public void WriteInExl(List<string> workList)
{
xlApp = new Excel.Application(); // open Excel App
xlWorkBookTar = xlApp.Application.Workbooks.Open(wrtFilePath); // open Workbook
//wrtBySht("InstrumentClassData");
foreach (string item in workList)
{
wrtBySht(item);
}
xlWorkBookTar.SaveAs(wrtFilePath, misValue, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlNoChange, misValue, misValue, misValue, misValue, misValue);
xlWorkBookTar.Close();
xlApp.Quit();
finProg();
}
示例8: Parse
public void Parse(object src, object dest)
{
if (src == null || string.IsNullOrEmpty(src.ToString()))
{
throw new ArgumentNullException("源文件不能为空");
}
if (dest == null || string.IsNullOrEmpty(dest.ToString()))
{
throw new ArgumentNullException("目标路径不能为空");
}
try
{
xlsx = excelApp.Workbooks.Open(src.ToString(), missing, missing, missing, missing, missing
, missing, missing, missing, missing, missing, missing, missing, missing, missing);
int startPage = 0;
int endPage = 10;
if (xlsx != null)
{
xlsx.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, dest, missing, missing, missing, missing, missing, missing,
missing);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (xlsx != null)
{
xlsx.Close(false, missing, missing);
xlsx = null;
}
if (excelApp!= null)
{
excelApp.Quit();
excelApp = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
示例9: LoadSheetName_RobPlan
private void LoadSheetName_RobPlan()
{
_xlApp = new Excel.Application {DisplayAlerts = false};
_xlWorkBook = _xlApp.Workbooks.Open(_pathRobPlan);
int countGroup = 0;
for (int i = 1; i <= _xlWorkBook.Sheets.Count; i++)
{
string name = _xlWorkBook.Worksheets.get_Item(i).Name;
if (name.Length != 8 || name.IndexOf('-') != 2) continue;
SheetNamesRobPlan[countGroup] = _xlWorkBook.Worksheets.get_Item(i).Name;
countGroup++;
}
_xlWorkBook.Close();
_xlApp.Quit();
}
示例10: readData
public List<string> readData()
{
prjList.Clear();
ExcelApp = new Excel.Application();
ExcelApp.Visible = false;
WorkBookExcel = ExcelApp.Workbooks.Open(_filePath, false); //открываем книгу
WorkSheetExcel = (Excel.Worksheet)WorkBookExcel.Sheets["Списки"]; //Получаем ссылку на лист 1
for (int i = 2; WorkSheetExcel.Cells[i, 1].Text.ToString() != ""; i++)
{
prjList.Add(WorkSheetExcel.Cells[i, 1].Text.ToString());
}
WorkBookExcel.Close(false, Type.Missing, Type.Missing);
ExcelApp.Quit();
GC.Collect();
return prjList;
}
示例11: Esegui
public void Esegui(string codiceCondominio, decimal importo, string siglaUtente)
{
object oMissing = System.Reflection.Missing.Value;
_thisApplication = new Excel.Application();
_thisApplication.Visible = _verbose;
_spesaturaWorkbook = _thisApplication.Workbooks.Open(_excelFullPath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
_spesaturaSheet = (Excel.Worksheet)_spesaturaWorkbook.Worksheets[1];
// Trovo la prima cella libera
int emptyRow = -1;
for (int i = 15; i < 250; i++)
{
string[] columnsIndex = Settings.Default.ColumnIndex.Split(';');
bool found = true;
for (int j = 0; j < columnsIndex.Length; j++)
{
if (((Excel.Range)_spesaturaSheet.Cells[i, int.Parse(columnsIndex[j])]).Value2 != null)
{
found = false;
break;
}
}
if (found)
{
emptyRow = i;
break;
}
}
if (emptyRow > -1)
{
string[] columnsIndex = Settings.Default.UpdatableColumnIndex.Split(';');
valorizzaCelle(emptyRow, int.Parse(columnsIndex[0]), _descrizione);
valorizzaCelle(emptyRow, int.Parse(columnsIndex[1]), DateTime.Today.ToShortDateString());
valorizzaCelle(emptyRow, int.Parse(columnsIndex[2]), importo);
valorizzaCelle(emptyRow, int.Parse(columnsIndex[3]), siglaUtente);
}
_spesaturaWorkbook.Close(true, Type.Missing, Type.Missing);
_thisApplication.Quit();
}
示例12: ExportToExcel
public string ExportToExcel(DocumentModel document,string savePath)
{
savePath = savePath + Path.GetRandomFileName().Replace('.', 'a') + ".xlsx";
myApp = new Excel.Application();
myApp.Visible = false;
myBook = myApp.Workbooks.Add();
mySheet = (Excel.Worksheet)myBook.Sheets[1];
var lastRow = mySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
WriteHeadTable(document.HeadTable, ref lastRow);
WriteActs(document.Acts, ref lastRow);
WriteTables(document.Tables, ref lastRow);
mySheet.Columns.AutoFit();
myBook.SaveAs(savePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
myBook.Close(false);
myApp.Quit();
return savePath;
}
示例13: excelWrite
public void excelWrite()
{
//if (File.Exists(_filePath))
//{
// File.Delete(_filePath);
// FileStream fs = File.Create(_filePath);
// fs.Close();
//}
int i=0;
ExcelApp = new Excel.Application();
ExcelApp.Visible = true;
WorkBookExcel = ExcelApp.Workbooks.Open(_filePath, false); //открываем книгу
WorkSheetExcel = (Excel.Worksheet)WorkBookExcel.Sheets[1]; //Получаем ссылку на лист 1
foreach (string n in _tNames)
{
RangeExcel = (Excel.Range)WorkSheetExcel.Cells[i + 1, 1];
RangeExcel.Value = _tNames[i];
RangeExcel = (Excel.Range)WorkSheetExcel.Cells[i + 1, 2];
RangeExcel.Value = _tTels[i];
RangeExcel = (Excel.Range)WorkSheetExcel.Cells[i + 1, 3];
RangeExcel.Value = _tTels2[i];
RangeExcel = (Excel.Range)WorkSheetExcel.Cells[i + 1, 4];
RangeExcel.Value = _tTels3[i];
RangeExcel = (Excel.Range)WorkSheetExcel.Cells[i + 1, 5];
RangeExcel.Value = _tEmail[i];
RangeExcel = (Excel.Range)WorkSheetExcel.Cells[i + 1, 6];
RangeExcel.Value = _tDiv[i];
RangeExcel = (Excel.Range)WorkSheetExcel.Cells[i + 1, 7];
RangeExcel.Value = _tPos[i];
i++;
}
WorkBookExcel.Close(true, Type.Missing, Type.Missing);
ExcelApp.Quit();
GC.Collect();
}
示例14: ExportToExcel_gp
//.........这里部分代码省略.........
xlWorkSheet.Cells[1, 12] = "ราคาทุนรวม";
xlWorkSheet.Range[xlWorkSheet.Cells[1, 13], xlWorkSheet.Cells[1, 13]].Merge();
xlWorkSheet.Range[xlWorkSheet.Cells[1, 13], xlWorkSheet.Cells[1, 13]].EntireColumn.ColumnWidth = 20;
xlWorkSheet.Range[xlWorkSheet.Cells[1, 13], xlWorkSheet.Cells[1, 13]].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
xlWorkSheet.Cells[1, 13] = "กำไร(ขาดทุน) รวม";
xlWorkSheet.Range[xlWorkSheet.Cells[1, 14], xlWorkSheet.Cells[1, 14]].Merge();
xlWorkSheet.Range[xlWorkSheet.Cells[1, 14], xlWorkSheet.Cells[1, 14]].EntireColumn.ColumnWidth = 15;
xlWorkSheet.Range[xlWorkSheet.Cells[1, 14], xlWorkSheet.Cells[1, 14]].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
xlWorkSheet.Cells[1, 14] = "ชื่อผู้ขาย";
xlWorkSheet.Range[xlWorkSheet.Cells[1, 15], xlWorkSheet.Cells[1, 15]].Merge();
xlWorkSheet.Range[xlWorkSheet.Cells[1, 15], xlWorkSheet.Cells[1, 15]].EntireColumn.ColumnWidth = 20;
xlWorkSheet.Range[xlWorkSheet.Cells[1, 15], xlWorkSheet.Cells[1, 15]].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
xlWorkSheet.Cells[1, 15] = "ชื่อลูกค้า";
xlWorkSheet.Range[xlWorkSheet.Cells[1, 16], xlWorkSheet.Cells[1, 16]].Merge();
xlWorkSheet.Range[xlWorkSheet.Cells[1, 16], xlWorkSheet.Cells[1, 16]].EntireColumn.ColumnWidth = 20;
xlWorkSheet.Range[xlWorkSheet.Cells[1, 16], xlWorkSheet.Cells[1, 16]].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
xlWorkSheet.Cells[1, 16] = gvGP.Columns[15].HeaderText;
xlWorkSheet.Range[xlWorkSheet.Cells[1, 17], xlWorkSheet.Cells[1, 17]].Merge();
xlWorkSheet.Range[xlWorkSheet.Cells[1, 17], xlWorkSheet.Cells[1, 17]].EntireColumn.ColumnWidth = 20;
xlWorkSheet.Range[xlWorkSheet.Cells[1, 17], xlWorkSheet.Cells[1, 17]].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
xlWorkSheet.Cells[1, 17] = gvGP.Columns[16].HeaderText;
object[,] oo = new object[dt_gp.Rows.Count, dt_gp.Columns.Count];
for (i = 0; i < dt_gp.Rows.Count; i++)
{
for (int j = 0; j < dt_gp.Columns.Count; j++)
{
string value = "";
try
{
decimal num = 0;
DateTime dateTime = new DateTime();
value = dt_gp.Rows[i][j].ToString();
if (DateTime.TryParse(value, out dateTime) && !Decimal.TryParse(value, out num))
{
oo[i, j] = (dateTime).ToOADate();
//xlWorkSheet.Cells[i + 2, j + 1] = (dateTime).ToOADate();
//xlWorkSheet.get_Range("A" + (i + 2), "A" + (j + 1)).NumberFormat = "dd-mm-yyyy";
//xlWorkSheet.get_Range("A" + (i + 2), "A" + (j + 1)).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
}
else
{
oo[i, j] = dt_gp.Rows[i][j].ToString();
//xlWorkSheet.Cells[i + 2, j + 1] = dt_gp.Rows[i][j].ToString();
}
}
catch (Exception ex)
{
}
}
}
string excelRange = string.Format("A2:{0}{1}",
findColumnLetter(dt_gp.Columns.Count), dt_gp.Rows.Count + 1);
xlWorkSheet.get_Range(excelRange, Type.Missing).Value2 = oo;
xlWorkSheet.get_Range("A2", "A" + dt_gp.Rows.Count + 1).NumberFormat = "dd-mm-yyyy";
xlWorkSheet.get_Range("G2", "G" + dt_gp.Rows.Count + 1).NumberFormat = "#,##0.00";
xlWorkSheet.get_Range("H2", "H" + dt_gp.Rows.Count + 1).NumberFormat = "#,##0.00";
xlWorkSheet.get_Range("I2", "I" + dt_gp.Rows.Count + 1).NumberFormat = "#,##0.00";
string fileName = String.Empty;
SaveFileDialog saveFileExcel = new SaveFileDialog();
saveFileExcel.FileName = "" + DBConnString.sDb + " GP ตั้งแต่วันที่ " + dateTimePicker1.Text + " ถึง " + dateTimePicker2.Text + " ";
saveFileExcel.Filter = "Excel files (*.xls,*.xlsx)|*.xls*";
saveFileExcel.FilterIndex = 2;
saveFileExcel.RestoreDirectory = true;
if (saveFileExcel.ShowDialog() == DialogResult.OK)
{
fileName = saveFileExcel.FileName;
xlWorkBook.SaveAs(fileName, 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);
this.Cursor = Cursors.Default;
MessageBox.Show("Export " + saveFileExcel.FileName + " Complete.");
}
else
{
return;
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
finally
{
System.Threading.Thread.CurrentThread.CurrentCulture = Oldcul;
this.Cursor = Cursors.Default;
}
}
示例15: ExportExcel
private void ExportExcel(string path)
{
bool success = false;
object misValue = System.Reflection.Missing.Value;
excelApp = new Microsoft.Office.Interop.Excel.Application();
if (excelApp == null) {
MessageBox.Show("Excel is not properly installed!!");
return;
}
worker = new BackgroundWorker();
worker.WorkerSupportsCancellation = true;
worker.WorkerReportsProgress = true;
PawnGuardDBDataContext pawnguard = new PawnGuardDBDataContext();
ProgStackPanel.Visibility = System.Windows.Visibility.Visible;
ProgTextCancel.Visibility = System.Windows.Visibility.Collapsed;
ProgressGrid.Visibility = System.Windows.Visibility.Visible;
StoneListGrid.Visibility = System.Windows.Visibility.Hidden;
Import.IsEnabled = false;
Export.IsEnabled = false;
this.MinHeight = 500;
ProgText.Text = "Exporting Data...";
ProgressStone.Value = 0;
worker.DoWork += delegate(object sdr, DoWorkEventArgs dw) {
Excel.Application _excelApp = (Excel.Application)dw.Argument;
xlWorkBook = _excelApp.Workbooks.Open(path);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
List<Stone> stones = pawnguard.Stones.ToList<Stone>();
for (int row = 0; row < stones.Count; row++) {
for (int col = 0; col < 13; col++) {
if (col == 0) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].rarity;
if (col == 1) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].name;
if (col == 2) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].carat;
if (col == 3) xlWorkSheet.Cells[row + 2, col + 1] = stones[row].price;
}
worker.ReportProgress(Convert.ToInt32(((decimal)row / (decimal)stones.Count) * 100));
System.Threading.Thread.Sleep(100);
if (worker.CancellationPending) {
ProgText.Dispatcher.Invoke(new Action(() => { ProgText.Text = "Canceling..."; }));
System.Threading.Thread.Sleep(2000);
dw.Cancel = true;
return;
}
}
};
worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args) {
ProgressStone.Value = args.ProgressPercentage;
};
worker.RunWorkerCompleted += delegate(object sdr, RunWorkerCompletedEventArgs rwc) {
if (rwc.Error != null) {
MessageBox.Show(rwc.Error.Message);
return;
}
if (!rwc.Cancelled) {
ProgressStone.Value = 100;
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = "Stone Template.xlsx";
dlg.DefaultExt = ".xlsx";
dlg.Filter = "Stone Template|*.xlsx";
Nullable<bool> result = dlg.ShowDialog();
if (result == true) {
string filename = dlg.FileName;
xlWorkBook.SaveAs(filename);
success = true;
path = filename;
}
} else {
ProgText.Dispatcher.Invoke(new Action(() => { ProgText.Text = "Cancelled"; }));
}
xlWorkBook.Close(true, misValue, misValue);
excelApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(excelApp);
ProgressGrid.Visibility = System.Windows.Visibility.Hidden;
StoneListGrid.Visibility = System.Windows.Visibility.Visible;
Import.IsEnabled = true;
Export.IsEnabled = true;
this.MinHeight = 300;
if (success) {
System.Diagnostics.Process.Start(path);
}
};
worker.RunWorkerAsync(excelApp);
}