开发者

Is there a simple way to get the "A1" style coordinates for a Range using the Excel COM interfaces?

开发者 https://www.devze.com 2023-03-21 05:53 出处:网络
I\'m trying to get my program to dump out data into an Excel spreadsheet. At the moment, it simply puts the information into the proper cell calculating any calculated values as needed within my code.

I'm trying to get my program to dump out data into an Excel spreadsheet. At the moment, it simply puts the information into the proper cell calculating any calculated values as needed within my code. What I would really like to do is instead of writing out the calculated values is to write out the Excel formulas to the cells that contain calculated values. That way, if I give the Excel document to someone, they can change the data in it and the calculated values will update as expected.

The probl开发者_开发知识库em is that I don't know how to get the "A1" style coordinates which Excel would expect. Basically, I'm hoping that there's something like this available:

calculatedCell.Value = string.Format("=SUM({0})", range.Coordinates);

I know I can get the row and column index for the range, and using those I could evaluate the coordinates myself, I was just hoping there was a pre-packaged way of doing it.


There should be an Address property on Range.

Try this:

calculatedCell.Value = string.Format("=SUM({0})", range.get_Address(true, true, 
                                                        XlReferenceStyle.xlA1,
                                                        false, null));
0

精彩评论

暂无评论...
验证码 换一张
取 消