Affichage bizzare sur Datagridview
Bonjour,
J'ai écrit une petite fonction qui convertit un fichier .xls en un DataTable, voici le code de cette fonction:
Code:
1 2 3 4 5 6 7 8 9 10 11
| public static DataTable Excel2DataTable(string chemin, string feuille)
{
DataTable dtExcel = new DataTable();
dtExcel.TableName = "MonFichier";
string SourceConstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + chemin + ";Extended Properties= 'Excel 8.0;HDR=Yes;IMEX=1'";
OleDbConnection con = new OleDbConnection(SourceConstr);
string query = "Select * from [" + worksheet + "$]";
OleDbDataAdapter data = new OleDbDataAdapter(query, con);
data.Fill(dtExcel);
return dtExcel;
} |
Cependant, quand j'affiche ce datatable sur un datagridviewle nom de certaines colonnes sont déformées.
Exemple: dans mon fichier excel l'une des colonnes est nommée ainsi Nom.Prénom, dans le datagridview ca m'affiche Nom#Prénom.
Voici le code que j'utilise pour afficher mon datatable.
Code:
1 2 3 4 5 6 7 8 9
| public Form1()
{
InitializeComponent();
DataTable dt = Tools.Excel2DataTable("C:/Users/user/Desktop/Fichier.xls", "feuil1");
dt = dt.DefaultView.ToTable(true, "Nom.Prénom", "Age");
dataGridView1.DataSource = dt;
} |
et dans mon Main j'ai mis:
Code:
1 2 3 4 5 6 7 8 9
|
static void Main(string[] args)
{
Form1 f = new Form1();
Application.EnableVisualStyles();
Application.Run(f);
} |
Merci de votre aide.