Thursday, June 11, 2009

VSTO : ListObjects

VSTO is not obvious, here is to name columns

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace ExcelWorkbook7
{
public partial class Feuil1
{
NorthwindDataContext ctx = new NorthwindDataContext();

private void Feuil1_Startup(object sender, System.EventArgs e)
{
var cs = from cust in ctx.Customers
select cust;

Microsoft.Office.Tools.Excel.ListObject customerData;
customerData = this.Controls.AddListObject(this.get_Range(this.Cells[1,1],this.Cells[1,2]), "Customers");
DataGridTableStyle s = new DataGridTableStyle();

customerData.TableStyle = "TableStyleLight10";
customerData.ListColumns.get_Item(1).Name = "ID";
customerData.ListColumns.get_Item(2).Name = "Name";
customerData.SetDataBinding(cs,"","CustomerID","CompanyName");

}

private void Feuil1_Shutdown(object sender, System.EventArgs e)
{
}

#region VSTO Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InternalStartup()
{

this.Startup += new System.EventHandler(this.Feuil1_Startup);
this.Shutdown += new System.EventHandler(this.Feuil1_Shutdown);

}

#endregion

}
}

How to programmatically display data into an excel worksheet

http://thedotnet.com/nntp/156520/showpost.aspx

Excel Object Model reference

http://msdn.microsoft.com/en-us/library/bb149081.aspx

VSTO : Add ListObject Controls to Worksheets

http://msdn.microsoft.com/en-us/library/eyfs6478(VS.80).aspx

Trie paramétrable

http://forum.hardware.fr/hfr/Programmation/CNET-managed/parametrable-list-sort-sujet_111411_1.htm