如何读取使用c#中的宏动态生成的单元格值? [英] How to read cell values that are dynamically generated using macros in c#?

查看:48
本文介绍了如何读取使用c#中的宏动态生成的单元格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





1.我有一个excel文件,其中一些单元格值是使用宏动态生成的。

2.文件也是只读的。

3.我必须使用c#代码读取这些动态生成的值。



使用以下宏代码生成单元格值:



Sub abc()

范围(E5)。值=字符串

范围(E6)。值= 2

结束子




谢谢...!

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...!

推荐答案

worksheet 

public Excel.Worksheet worksheet1 = null;





记住你需要将excel加载到工作表1



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







remeber you need to load the excel into worksheet1

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


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;


仍然没有使用上面的代码。
Still its not working with above code.


这篇关于如何读取使用c#中的宏动态生成的单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆