C# automating Excel - need help RRS feed

  • Question

  • Hi all,

    I am in the process of making an application that puts data (specifically the time) in an excel document when a button is pressed. I have added the Excel reference and everything like that. Here is what I have.

            private void button1_Click(object sender, EventArgs e)
                Excel.Application objExcel = new Excel.Application();
                objExcel.Visible = true;

                //start new workbook/worksheet;

                Excel.Workbook objBook = objExcel.Workbooks.Add(System.Reflection.Missing.Value);
                Excel.Worksheet objSheet = (Excel.Worksheet)objBook.Worksheets.get_Item(1);

                Excel.Range objRange;

                objRange = objSheet.get_Range("B2", System.Reflection.Missing.Value);
                objRange.set_Value(lblClock.Text);  // <----- ********* lblClock *************

    You see lblClock.Text? That displays the current time (I have it synced with a timer control). How do I get that text into a cell in Excel? Thanks for any help.
    • Moved by jack 321 Tuesday, June 17, 2008 7:19 AM off topic
    Friday, June 13, 2008 1:44 PM


All replies