Assigning a cells value programmatically

Posted by: j2associates on 8 September 2017, 12:30 pm EST

  • Posted 8 September 2017, 12:30 pm EST


    Do you guys recommend one or the other of the following functionally equivalent ways to assign a cell's value or is it just personal preference? Thanks!

    <FONT size=2>

    SetValue(m_LastHeaderRow, m_ColumnGroupID, newGuid)

    <FONT size=2>

    Cells(m_LastHeaderRow, m_ColumnGroupID).Value = newGuid

  • Replied 8 September 2017, 12:30 pm EST


    If you are inquiring about the SetValue method on the SheetView object, then these lines of code are practically equivalent. However, there is also a SetValue method on the DefaultSheetDataModel object that both your lines of code is actually calling underneath, so it would be faster to call that method instead of the wrapper functions you mentioned in your post.

  • Replied 8 September 2017, 12:30 pm EST

    Thanks! As usual a very concise and informative answer. How would I reference the model properties you refer to in your response. I typically do something along the lines of

    With Me.FpSpread1.ActiveSheet
        .Cells(e.Row, e.Column), etc
    End With

    Should I be doing this another way? Thanks again!

  • Replied 8 September 2017, 12:30 pm EST


    There is a chapter in the Developer's Guide titled Using Sheet Models. This information should be good information about how to program against the models. This is the intended use of .NET development, but we had some many customers moving from programming against COM objects, that this was completely different. So, we wrote wrapper classes (which you are using in the code snipets you have sent) that call into the object models to do things to the Spread. This would make processing of the code slower, since there is two or more calls being made for every line of code working with the Spread object. However, the code looks familiar to someone who is use to COM programming, which is why we created the wrapper class.

    Take a look at our AgedReceivables sample as well. This shows programming using the wrapper class and against the models, so you can see first of all how to do this, but also it shows how much faster programming against the models the executable is.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels