Skip to content

Instantly share code, notes, and snippets.

@jnericks
Created July 13, 2011 21:23
Show Gist options
  • Save jnericks/1081367 to your computer and use it in GitHub Desktop.
Save jnericks/1081367 to your computer and use it in GitHub Desktop.
Application xlApp;
Workbooks xlBooks;
Workbook xlBook;
Worksheet xlSheet;
public IndexUpdaterExcelService()
{
try
{
try
{
xlApp = (Application)Marshal.GetActiveObject("Excel.Application");
}
catch
{
xlApp = new Application();
}
xlApp.DisplayAlerts = false;
xlBooks = xlApp.Workbooks;
xlBook = xlBooks.Count > 0
? xlBooks[1]
: xlBooks.Open(_fileNameAndPath);
xlSheet = (Worksheet)xlBook.Worksheets[1];
xlApp.Visible = true;
}
catch (Exception e)
{
Log.Error(e.Message);
Log.Error(@"Unable to Connect to '{0}' Please open the file and restart this app.".FormatWith(_fileNameAndPath));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment