none
How to resize an excel table

    Question

  • I am building an excel 2007 add-in on visual studio professional 2008 with SP1. I want my add-in to add and remove data to a certain excel table.

    Excel.Range rg = ws.get_Range("myExcelTable", System.Type.Missing);
    rg.Value2 = string.Empty;
    rg.Value2 = myArray;

     

    If the table has less rows than the array, the table doesnt reisze and so the last rows of the array are not copied into excel.
    If the table has more rows than the array, the rows are repeated in the table.

    So, I need to resize the table to fit the array and, after that, copy the array to the table. No missing data and no surplus data.
    How can I do this?

    Thursday, April 02, 2009 12:42 AM

Answers

  • I actually created a listobject from my existing excel table with
    Tools.ListObject.GetVstoObject(ws.ListObjects.get_Item("myExcelTable"));
    and then used the SetDataBinding method.
    • Marked as answer by bouvierr Thursday, April 02, 2009 9:26 PM
    Thursday, April 02, 2009 9:25 PM

All replies

  • Hello,
    You could create a ListObject for the table, and then resize the ListObject to include the correct number of rows. Here is a topic about how to resize a List Object - http://msdn.microsoft.com/en-us/library/afxz16c3.aspx.
    Norm Estabrook
    Thursday, April 02, 2009 6:11 PM
    Answerer
  • I actually created a listobject from my existing excel table with
    Tools.ListObject.GetVstoObject(ws.ListObjects.get_Item("myExcelTable"));
    and then used the SetDataBinding method.
    • Marked as answer by bouvierr Thursday, April 02, 2009 9:26 PM
    Thursday, April 02, 2009 9:25 PM