views:

269

answers:

1

Question1: How to access windows form and its controls on VSTO excel using C#?

Question2: On Execution of VSTO Excel workbook application, I want total no. of active columns when the user paste the data. Suppose User may paste 5 column data or 10 column data. Through code i want to figure out the total no. of columns(Also Total no. of rows if possible) once the user pastes/loads the tabular data. How to get indefinite range value for cells on execution of VSTO excel when data is pasted on the same.

Please help me with code for these two questions.

+1  A: 

Q1: Same as you do in a winforms application, when you create the windows form, keep a reference to it. Make sure to expose property accessors (get;set;) for the form.

Q2: You need to implement a AppEvents_SheetChangeEventHandler and assign to Globals.ThisAddin.Application.SheetChange event property. In the event handler, the second argument is Excel.Range TargetRange. TargetRange is the Excel.Range object containing the pasted information. The range.Columns.Count property gets you the total columns in the pasted, range.Rows.Count gets you the total rows in the pasted.

Not sure what you mean by "how to get indefinite range value for cells". Can you clarify?

code4life