Imprimer

yoyohoho Messages postés 4 Date d'inscription jeudi 16 février 2006 Statut Membre Dernière intervention 15 août 2006 - 25 juil. 2006 à 02:21
yoyohoho Messages postés 4 Date d'inscription jeudi 16 février 2006 Statut Membre Dernière intervention 15 août 2006 - 25 juil. 2006 à 16:36
salut,j ai une base de donnee sql server 2005 express que je l ai connecte avec mon IDE visual C# pour la modifier et la consulter.maintenant je veux savoir comment je peux imprimer les donnees de ma base de donnees dans un format precis, par exemple creer un tableau Excel et le remplir avec les donnees d une maniere automatique c-a-d j ai le format du tableau et une case pour entrer un code et appartir de ce code je dois remplir le tableau  par les donnees  correspondantes.

5 réponses

MorpionMx Messages postés 3466 Date d'inscription lundi 16 octobre 2000 Statut Membre Dernière intervention 30 octobre 2008 57
25 juil. 2006 à 09:44
Salut

Et bien tu pourrais peut-etre simplement faire de l'automation office.
Tu crees ton document Excel, le rempli, et l'imprime.

Mx
MVP C# 
0
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
25 juil. 2006 à 10:47
ou simplement générer un fichier XML (excel ML par exempl) de tes données...

ensuite tu l'ouvres avec Excel.

Sébastien FERRAND (
blog)
Consultant Indépendant
[Microsoft MVP Visual C#]
0
Moomoon07 Messages postés 223 Date d'inscription mercredi 31 mai 2006 Statut Membre Dernière intervention 5 mai 2014
25 juil. 2006 à 15:10
CECI POURRA PEUT ETRE T'AIDER, C UNE CLASSE DE MA CREATION QUI PERMET DE RECOPIER UN DATAGRIDVIEWBOX DANS UNE FEUILLE EXCEL QUEL QUE SOIENT LE NOMBRE DE LIGNES ET DE COLONNES ; CE QUI EST COMPLIQUE C QU'IL Y A 36000 COULEUR DE CASES DE DATAGRID ET SEULEMENT UNE 50AINE DE COULEURS DANS EXCEL, DONC CA RECOPIE LA COMPOSANTE PRINCIPALE DE LA COULEUR;

using



System;


using



System.Collections;


using



System.Text;


using



System.Data.Common;


using



System.Data.OleDb;


using



System.Data.Sql;


using



System.Data.SqlClient;


using



System.Drawing;


using



System.Data;


using



System.Windows.Forms;


using



System.IO;


using



System.ComponentModel; 



namespace



OptiInfo{


class



Impression

{







//string OPTI_INFO_A = "c:\\Program Files\\Opti Info Gestion\\OPTI_INFO_A.txt";






private



ConfigForm
CF =

new



ConfigForm
();


public



string
CheminDocs(){


//string Chemin = "";






//try






//{






// using (StreamReader sr = new StreamReader(OPTI_INFO_A))






// {






// string line;






// while ((line = sr.ReadLine()) != null)






// {






// Chemin = line.ToString();






// }






// }






//}






//catch { }






return
CF.getCheminDOCS();}


private



string
LettreFromIndice(

int
Indice){


string
Colonne=

""
;


int
j = Indice;


if
(j 0)Colonne


"A"
;


else



if
(j 1)Colonne


"B"
;


else



if
(j 2)Colonne


"C"
;


else



if
(j 3)Colonne


"D"
;


else



if
(j 4)Colonne


"E"
;


else



if
(j 5)Colonne


"F"
;


else



if
(j 6)Colonne


"G"
;


else



if
(j 7)Colonne


"H"
;


else



if
(j 8)Colonne


"I"
;


else



if
(j 9)Colonne


"J"
;


else



if
(j 10)Colonne


"K"
;


else



if
(j 11)Colonne


"L"
;


else



if
(j 12)Colonne


"M"
;


else



if
(j 13)Colonne


"N"
;


else



if
(j 14)Colonne


"O"
;


else



if
(j 15)Colonne


"P"
;


else



if
(j 16)Colonne


"Q"
;


else



if
(j 17)Colonne


"R"
;


else



if
(j 18)Colonne


"S"
;


else



if
(j 19)Colonne


"T"
;


else



if
(j 20)Colonne


"U"
;


else



if
(j 21)Colonne


"V"
;


else



if
(j 22)Colonne


"W"
;


else



if
(j 23)Colonne


"X"
;


else



if
(j 24)Colonne


"Y"
;


else



if
(j 25)Colonne


"Z"
;


return
Colonne.ToString();}


public
Impression(

string
Titre,

DataGridView
Data){


try

{







//UseWaitCursor = true;






object
Missing = System.Reflection.

Missing
.Value;


String
fileName = CheminDocs() +

"Vierge.xls"
;Microsoft.Office.Interop.Excel.


_Application
xlApp;Microsoft.Office.Interop.Excel.


_Workbook
xlClasseur;Microsoft.Office.Interop.Excel.


_Worksheet
xlFeuill;xlApp =


new
Microsoft.Office.Interop.Excel.

Application
();xlApp.Visible =


true
;xlClasseur = xlApp.Workbooks.Open(fileName,

Missing, Missing, Missing, Missing,

Missing, Missing, Missing, Missing,

Missing, Missing, Missing, Missing,

Missing, Missing);

Microsoft.Office.Interop.Excel.


Sheets
xlFeuilles xlClasseur.Sheets;xlFeuill (Microsoft.Office.Interop.Excel.


_Worksheet
)xlFeuilles[

"A"
];Microsoft.Office.Interop.Excel.


Range
r;r = xlFeuill.get_Range(


"A1"
, Missing);r.set_Value(Microsoft.Office.Interop.Excel.


XlRangeValueDataType
.xlRangeValueDefault, Titre.ToString());r = xlFeuill.get_Range(


"A2"
, Missing); r.set_Value(Microsoft.Office.Interop.Excel.


XlRangeValueDataType
.xlRangeValueDefault,

"Imprim‚ le "
+

DateTime
.Now.ToString().Substring(0,10));


int
ligne=6;


int
Cl=0;


string
champ=

""
;


//.Affichage des noms de colonne






foreach
(

DataGridViewColumn
clm

in
Data.Columns){


if
(clm.Visible){

champ = LettreFromIndice(Cl) +


"4"
;r = xlFeuill.get_Range(champ, Missing);

r.set_Value(Microsoft.Office.Interop.Excel.


XlRangeValueDataType
.xlRangeValueDefault, clm.HeaderText.ToString());Cl++;

}

}


//.Remplissage des lignes






foreach
(

DataGridViewRow
dr

in
Data.Rows){


try

{







for
(

int
j = 0; j < Data.ColumnCount; j++){

champ = LettreFromIndice(j) + ligne.ToString();

r = xlFeuill.get_Range(champ, Missing);


try

{


r.set_Value(Microsoft.Office.Interop.Excel.




XlRangeValueDataType
.xlRangeValueDefault, dr.Cells[j].Value.ToString());


//MessageBox.Show(dr.Cells[j].Style.BackColor.ToArgb().ToString());

r.Interior.ColorIndex =




this
.getCouleurExcel(System.

Convert
.ToInt32(dr.Cells[j].Style.BackColor.R),System.

Convert
.ToInt32(dr.Cells[j].Style.BackColor.G),System.

Convert
.ToInt32(dr.Cells[j].Style.BackColor.B));


//r.Font.FontStyle = Color.FromName(dr.Cells[j].Style.Font.Style.ToString());

}







catch

{







if
(System.

Convert
.ToBoolean(dr.Cells[j]))r.set_Value(Microsoft.Office.Interop.Excel.


XlRangeValueDataType
.xlRangeValueDefault,

"Oui"
);


else

r.set_Value(Microsoft.Office.Interop.Excel.




XlRangeValueDataType
.xlRangeValueDefault,

"Non"
); }

}

}


catch
{ }ligne++;

}


//xlFeuill.Columns.Width






//UseWaitCursor = false;

}







catch
{

MessageBox
.Show(

"Impossible d'ouvrir le document Excel type : Vierge.xls"
); }}


public



int
getCouleurExcel(

int
R,

int
G,

int
B){


//MessageBox.Show(R.ToString()+"/"+G.ToString()+"/"+B.ToString());






if
(R 0 && G 0 && B == 0)


return
2;


else



if
(R > G && R > B)


return
3;


else



if
(G > B)


return
4;


else



return
5;}

}

}








MMN
0
Moomoon07 Messages postés 223 Date d'inscription mercredi 31 mai 2006 Statut Membre Dernière intervention 5 mai 2014
25 juil. 2006 à 15:13
et voila un exemple d'appel :

private
void bImpFactures_Click(
object sender,
EventArgs e)
{

Impression IMP =
new
Impression(
"FACTURES DU " + dDebut.Value.ToString().Substring(0, 10) +
" AU " + dFin.Value.ToString().Substring(0, 10), dataFactures);
}
t'as juste a refaire getCheminDoc, qui retourne le dossier dans lequel se trouve ton document excel vierge.xls

MMN
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
yoyohoho Messages postés 4 Date d'inscription jeudi 16 février 2006 Statut Membre Dernière intervention 15 août 2006
25 juil. 2006 à 16:36
je voudrai savoir comment generer un fichier xml de mes donnees pour les transporters a un fichier excel pour ensuite les imprimers dans un format precis si j ai bien compris ce qu il a dit monsieur "sebmafate" et s il y a un document pour cela c mieux
0
Rejoignez-nous