Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

c# - Access excel cell by its name

I'm trying to set excel's cell name to some custom name and to later access that cell by its name. Is there some out of the box API call to do this, or how should I do this if I have information of worksheet and cell name in case of accessing cell and worksheet and cell address (i.e. C2) in case of naming the cell.

Also to ask, is there a way to acquire formatting information that is bound to that specific cell? (i.e. When I'm accessing cell by name I want to return cell value and some formatting properties of this cell, if cell is number or text, is it highlighted, etc...)

regards,

Vladimir Vajda

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you may be looking for Range("C2").

As to formatting information, this is available through various properties of the Excel object model. See http://msdn.microsoft.com/en-us/library/ff197454.aspx for more information.

The Range type (as opposed to the Range indexed property referenced above) also exposes a Name property, which you can set in code:

worksheet.get_Range("C2").Name = "fdafdfs"
worksheet.get_Range("fdafdfs").Select();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...