Click here to Skip to main content
15,887,436 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

1. I have an excel file in which some cell values are generating dynamically using macro.
2. File is also read-only.
3. I have to read these dynamically generated values using c# code.

Use following macro code to generate cell values:

Sub abc()
Range("E5").Value = "string"
Range("E6").Value = 2
End Sub


Thank You...!
Posted
Comments
ZurdoDev 15-Oct-15 9:39am    
What exactly is your question? Getting the value is as easy is doing
someVal = Range("E5").Value
BillWoodruff 15-Oct-15 15:00pm    
Is the problem that you don't know the Row/Column addresses of which cells have been created by the Macro ?

when
C#
worksheet 
is
C#
public Excel.Worksheet worksheet1 = null;


remeber you need to load the excel into worksheet1

-------------------------------------------------


C#
public ReadExcelDoc(string filename)
        {
            app = new Excel.Application();
            workbook = app.Workbooks.Open(filename, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            worksheet1 = (Excel.Worksheet)workbook.Worksheets.get_Item(1);
            worksheet2 = (Excel.Worksheet)workbook.Worksheets.get_Item(2);
            String or int or double as you need = readData(1, 1, worksheet1);
            Close();
        }



public double readData(int row, int col, Excel.Worksheet worksheet)
        {
            Object data;

            workSheet_range = (Excel.Range)worksheet.Cells[row, col];
            data = (System.Object)workSheet_range.get_Value(Missing.Value);
            return Convert.ToDouble(data);
        }

 private object misValue = System.Reflection.Missing.Value;
 
Share this answer
 
v4
Still its not working with above code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900