Click here to Skip to main content
15,891,375 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to contact with Mr.Sergey Alexandrovich Pin
Pete O'Hanlon28-Nov-13 1:17
mvePete O'Hanlon28-Nov-13 1:17 
GeneralRe: How to contact with Mr.Sergey Alexandrovich Pin
Richard MacCutchan28-Nov-13 1:24
mveRichard MacCutchan28-Nov-13 1:24 
AnswerRe: How to contact with Mr.Sergey Alexandrovich Pin
Richard MacCutchan28-Nov-13 0:01
mveRichard MacCutchan28-Nov-13 0:01 
AnswerRe: How to contact with Mr.Sergey Alexandrovich Pin
GuyThiebaut28-Nov-13 0:55
professionalGuyThiebaut28-Nov-13 0:55 
GeneralRe: How to contact with Mr.Sergey Alexandrovich Pin
Pete O'Hanlon28-Nov-13 1:10
mvePete O'Hanlon28-Nov-13 1:10 
GeneralRe: How to contact with Mr.Sergey Alexandrovich Pin
_Maxxx_28-Nov-13 19:42
professional_Maxxx_28-Nov-13 19:42 
AnswerRe: How to contact with Mr.Sergey Alexandrovich Pin
Abhinav S28-Nov-13 3:24
Abhinav S28-Nov-13 3:24 
QuestionExcel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 20:26
emma.sun.sts27-Nov-13 20:26 
I need to create excel file and email it once every month. I've got my windows service working. I've got standalone my excel file creation and saving without user prompt working. But when I try to create excel inside windows service, excel file isn't created at all without any error message in the event log. Below is my code. Can someone please enlighten me what goes wrong? Thanks in advance!

private void weeklyTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            eventLog1.WriteEntry("W event elapsed @ " + e.SignalTime); //<<---Debug
            createXLS(dirXLS_W);                      
        }//-----------------------------------------------------------------------
		
		 private void createXLS(string dir) //call before connection closes 
        {
            string data = null;
            Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlApp = new Excel.Application();
            xlApp.DisplayAlerts = false;
            xlWorkBook = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            eventLog1.WriteEntry("Xls worksheet created."); //<<------------------debug
            xlWorkSheet.Cells[1, 2] = "Date"; 
			// .. cells created etc. 
            
            try
            {
                xlWorkBook.SaveAs(dir, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, true, false, Excel.XlSaveAsAccessMode.xlNoChange,
                                   Excel.XlSaveConflictResolution.xlLocalSessionChanges, misValue, misValue);
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                eventLog1.WriteEntry("Excel file is saved under " + dir); //<<-debug
            }
            catch (Exception e)
            {
                eventLog1.WriteEntry("createXLS error: " + e.ToString());
            }
            
            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);
        }//--------------------------------------------------------
		
		private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception e3)
            {
                obj = null;
                eventLog1.WriteEntry("Exception Occured while releasing object " + e3.ToString());
            }
            finally
            {
                GC.Collect();
            }
        } //-------------------------------------------------------------------------

AnswerRe: Excel file creation and saving in Windows Service doesn't work. Pin
Bernhard Hiller27-Nov-13 21:13
Bernhard Hiller27-Nov-13 21:13 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 21:47
emma.sun.sts27-Nov-13 21:47 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Mycroft Holmes27-Nov-13 22:04
professionalMycroft Holmes27-Nov-13 22:04 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 22:10
emma.sun.sts27-Nov-13 22:10 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 22:17
emma.sun.sts27-Nov-13 22:17 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Pete O'Hanlon27-Nov-13 22:15
mvePete O'Hanlon27-Nov-13 22:15 
AnswerRe: Excel file creation and saving in Windows Service doesn't work. Pin
Abhinav S27-Nov-13 22:10
Abhinav S27-Nov-13 22:10 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 22:24
emma.sun.sts27-Nov-13 22:24 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Pete O'Hanlon27-Nov-13 22:30
mvePete O'Hanlon27-Nov-13 22:30 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 23:07
emma.sun.sts27-Nov-13 23:07 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Pete O'Hanlon27-Nov-13 23:18
mvePete O'Hanlon27-Nov-13 23:18 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 23:30
emma.sun.sts27-Nov-13 23:30 
AnswerRe: Excel file creation and saving in Windows Service doesn't work. Pin
Richard Deeming28-Nov-13 1:01
mveRichard Deeming28-Nov-13 1:01 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 14:53
emma.sun.sts28-Nov-13 14:53 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 15:19
emma.sun.sts28-Nov-13 15:19 
SuggestionRe: Excel file creation and saving in Windows Service doesn't work. Pin
Eddy Vluggen28-Nov-13 10:16
professionalEddy Vluggen28-Nov-13 10:16 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 14:46
emma.sun.sts28-Nov-13 14:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.