vsto to fill data use listobject fill

        public void btnFormatTables(Office.IRibbonControl control)
        {
            var sheet = (InteropExcel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet;
            var vstoSheet = Globals.Factory.GetVstoObject(sheet);
            var vstoListObject = vstoSheet.Controls.AddListObject(vstoSheet.Range["A1", "B3"], "list1");

            var table = new System.Data.DataTable("Employees");
            table.Columns.Add("FirstName", typeof(string));
            table.Columns.Add("LastName", typeof(string));
            table.Columns.Add("Title", typeof(string));

            table.Rows.Add("Nancy", "Anderson", "Sales Representative");
            table.Rows.Add("Robert", "Brown", "Sales Representative");

            vstoListObject.AutoSetDataBoundColumnHeaders = true;
            vstoListObject.SetDataBinding(table, "", "Title", "LastName", "FirstName");
            vstoListObject.Disconnect();

        }

 

posted @ 2013-03-12 22:35  I'm CY  阅读(287)  评论(0编辑  收藏  举报