Read values from a excel cell with addin formula using Excel automation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Read values from a excel cell with addin formula using Excel automation

  1. #1
    Join Date
    May 2003
    Posts
    4

    Read values from a excel cell with addin formula using Excel automation

    we are trying to retrieve a calculated value from a cell which has add-In (VBA) formulas in it. The sample add-in "myUtilityl.xla" is working properly in excel. It retrieves value for the addin function =ISOWEEKNUM(F9). But we are unable to retrieve the value in our application using C# & Microsoft Object Library. The add-In "myUtilityl.xla" is attached to Excel. Environment is VS2010
    I am providing the sample code here.

    string path = @"C:\Test.xls";
    Workbook theWorkbook;
    Worksheet theWorksheet;
    Range readRange;
    Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
    theWorkbook = app.Workbooks.Open(path);
    Sheets theSheets = (Sheets)theWorkbook.Worksheets;
    theWorksheet = (Worksheet)theWorkbook.Worksheets.get_Item("Sheet1");
    readRange = theWorksheet.get_Range("B1");
    MessageBox.Show(Convert.ToString(readRange.Value));
    //theWorkbook.Save();
    app.Workbooks.Close();
    I am new to Microsoft Object library. Any help or clue will be very helpful.
    Regards,
    Jinto.

  2. #2
    Join Date
    May 2002
    Location
    Boston
    Posts
    66

    Re: Read values from a excel cell with addin formula using Excel automation

    Hi,

    You're trying to convert a range to a double.

    try this

    Code:
    readRange = theWorksheet.get_Range("C1", "C1");
                   
    double readValue;
    readValue = Convert.ToDouble(readRange.Value2); 
                   
      
    MessageBox.Show(Convert.ToString(readValue));
    Curt

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center