public void ExportMeasurements()
{
// A new application needs to be created.
Excel.Application excelApp = new Excel.ApplicationClass();
// See if the file exists and has correct extension
if (!File.Exists(this.cExcelFile))
{
excelApp.Quit();
excelApp = null;
throw new FileNotFoundException("{0} does not exist.", this.cExcelFile);
}
if (excelApp == null)
{
throw new Exception("Error! Excel Failed to Initailize");
}
// Open an existing document into a Workbook object:
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(this.cExcelFile,
Excel.XlUpdateLinks.xlUpdateLinksUserSetting, false, 5, "", "", false, Excel.XlPlatform.xlWindows,
"", true, false, 0, true, false, false);
// Count the sheets in collection.
if (cSheets.Count == 0 || cSheets == null)
{
throw new NotSupportedException("No Sheet Specified.");
}
// Get all of the sheets in the workbook opened.
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
// Now that you have the collection of Worksheets, you must get an individual sheet edit data within.
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(cSheets[0].ToString());
ICollection IMasterKeys = cMasterDrill.GetKeys();
ICollection ISlaveKeys = cSlaveDrill.GetKeys();
// Make sure that the key counts match for both drils.
if (ISlaveKeys.Count != IMasterKeys.Count)
{
excelApp.Quit();
excelApp = null;
throw new ArgumentOutOfRangeException("IMasterKeys (" + IMasterKeys.Count + ") != ("
+ ISlaveKeys.Count + ") IBaseKeys.");
}
foreach (object itMaster in IMasterKeys)
{
// Load well stats into arraylist.
ArrayList masterList = GetMeasurements(itMaster.ToString());
foreach (object itSlave in ISlaveKeys)
{
// Load well stats into arraylist.
ArrayList slaveList = GetMeasurements(itSlave.ToString());
[b]//ERRORS HERE
//Finding the cell containing the specified string
try
{
Excel.Range rng = excelWorksheet.Cells.Find("LA 10004", null, null,
Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext,
null, null, null);
}
catch (Exception e)
{
}[/b]
}
}
// Close out of excel.
excelWorkbook = null;
excelWorksheet = null;
excelSheets = null;
excelApp.Quit();
excelApp = null;
}
}