Click here to Skip to main content
16,019,152 members
Home / Discussions / C#
   

C#

 
QuestionRe: Passing one of struct (from array) to other method (in different files) Pin
MicroVirus22-Jun-11 5:55
MicroVirus22-Jun-11 5:55 
AnswerRe: Passing one of struct (from array) to other method (in different files) Pin
Blubbo22-Jun-11 7:03
Blubbo22-Jun-11 7:03 
AnswerRe: Passing one of struct (from array) to other method (in different files) Pin
MicroVirus22-Jun-11 8:29
MicroVirus22-Jun-11 8:29 
AnswerRe: Passing one of struct (from array) to other method (in different files) Pin
David198722-Jun-11 6:26
David198722-Jun-11 6:26 
QuestionFile copy onto remote server of different domain with credentials. Pin
surender.m22-Jun-11 3:27
surender.m22-Jun-11 3:27 
AnswerRe: File copy onto remote server of different domain with credentials. Pin
Mario Majčica22-Jun-11 4:44
professionalMario Majčica22-Jun-11 4:44 
GeneralRe: File copy onto remote server of different domain with credentials. [modified] Pin
surender.m22-Jun-11 18:38
surender.m22-Jun-11 18:38 
QuestionNeed help with excel and com objects in c sharp Pin
turbosupramk322-Jun-11 3:08
turbosupramk322-Jun-11 3:08 
I am having a problem where when my c sharp program opens and closes excel, it leaves a reference to Excel.exe in the task manager running after I call the program to close in my code. After searching, I found the following information, but I need help implementing it into this method.

The link says that an com object with more than 1 child method per variable assignment gives the garbage collector problems. Is anyone able to rewrite the code (or at least get me started) below to have more variables and only 1 child method per variable?

Thanks for reading!

http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c[^]

Excel.Application xlApp;
    Excel.Workbook xlWorkBook;
    Excel.Worksheet xlWorkSheet;
    public string dateRan = "";
    public string timeRan = "";
    public string userRan = "";

 private void writeExcel(string data, int row, int column, bool createSheet, bool closeSheet, bool carriageReturn)
    {
        if (createSheet == true)
        {
            dateRan = loggingClass.returnDate(false, true);
            timeRan = loggingClass.returnTime(false, false, true);
            userRan = System.Environment.UserName;
            xlApp = new Excel.ApplicationClass();
            xlWorkBook = xlApp.Workbooks.Add(Missing.Value);


            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);


            xlWorkSheet.Cells[2, 1] = "User:";
            xlWorkSheet.Cells[2, 2] = System.Environment.UserName;
            xlWorkSheet.Cells[3, 1] = "Date ran:";
            xlWorkSheet.Cells[3, 2] = dateRan;
            xlWorkSheet.Cells[4, 1] = "Time ran:";
            xlWorkSheet.Cells[4, 2] = timeRan;
        }
        else
        {


            if (data == "pass")
            {
                xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Green);
            }

            if (data == "fail")
            {
                xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
            }

            if (data == "manual")
            {
                xlWorkSheet.get_Range("A" + row, "Z" + row).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
            }
            xlWorkSheet.Cells[row, column] = data;

            xlApp.Visible = true; // Shows excel spreadsheet while creating it


            if (closeSheet == true)
            {
                xlWorkSheet.Application.ActiveWindow.SplitRow = 1;
                xlWorkSheet.Application.ActiveWindow.FreezePanes = true;
                xlWorkSheet.get_Range("A1", "Z1").Font.Bold = true;
                xlWorkSheet.Columns.AutoFit();
                xlWorkSheet.Rows.AutoFit();
                xlWorkBook.SaveAs(@"c:\temp\log_" + dateRan.Replace("/", "-") + "__" + timeRan.Replace(":", ".") + ".xls", Excel.XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                xlWorkBook.Close(true, Missing.Value, Missing.Value);
                xlApp.Quit();
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);

            }
        }
    }

AnswerRe: Need help with excel and com objects in c sharp Pin
BobJanova22-Jun-11 4:20
BobJanova22-Jun-11 4:20 
GeneralRe: Need help with excel and com objects in c sharp Pin
turbosupramk322-Jun-11 8:09
turbosupramk322-Jun-11 8:09 
GeneralRe: Need help with excel and com objects in c sharp Pin
BobJanova22-Jun-11 8:12
BobJanova22-Jun-11 8:12 
QuestionHow to detect invalid character input in ListView control? Pin
ShadowUz21-Jun-11 20:06
ShadowUz21-Jun-11 20:06 
AnswerRe: How to detect invalid character input in ListView control? Pin
Mario Majčica21-Jun-11 22:26
professionalMario Majčica21-Jun-11 22:26 
GeneralRe: How to detect invalid character input in ListView control? Pin
ShadowUz21-Jun-11 23:40
ShadowUz21-Jun-11 23:40 
AnswerRe: How to detect invalid character input in ListView control? Pin
Mario Majčica21-Jun-11 23:44
professionalMario Majčica21-Jun-11 23:44 
QuestionSerialize Class To Xml & Store In Sql Pin
Kevin Marois21-Jun-11 15:39
professionalKevin Marois21-Jun-11 15:39 
AnswerRe: Serialize Class To Xml & Store In Sql Pin
Not Active21-Jun-11 16:30
mentorNot Active21-Jun-11 16:30 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Kevin Marois21-Jun-11 17:41
professionalKevin Marois21-Jun-11 17:41 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Mycroft Holmes21-Jun-11 18:54
professionalMycroft Holmes21-Jun-11 18:54 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Kevin Marois22-Jun-11 3:51
professionalKevin Marois22-Jun-11 3:51 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
BobJanova22-Jun-11 4:15
BobJanova22-Jun-11 4:15 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Kevin Marois22-Jun-11 5:10
professionalKevin Marois22-Jun-11 5:10 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Mark Salsbery22-Jun-11 8:26
Mark Salsbery22-Jun-11 8:26 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
AspDotNetDev22-Jun-11 8:44
protectorAspDotNetDev22-Jun-11 8:44 
AnswerRe: Serialize Class To Xml & Store In Sql Pin
jschell22-Jun-11 9:21
jschell22-Jun-11 9:21 

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.