Bordure de cellule excel

Résolu
cs_Marquo Messages postés 31 Date d'inscription vendredi 22 août 2003 Statut Membre Dernière intervention 14 octobre 2005 - 22 août 2005 à 11:14
delphi2004 Messages postés 6 Date d'inscription jeudi 26 février 2004 Statut Membre Dernière intervention 29 décembre 2008 - 31 mars 2010 à 22:16
Bonjour,

je dois faire une application Excel avec C# mais avant de me lancer j'aimerais savoir d'une part si il est possible de tracer des bordures pour les cellules et d'autre part si il est possible de dupliquer une ligne ?

Merci

9 réponses

sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
22 août 2005 à 11:45
la meilleur solution... c'est d'enregistrer une macro... et ensuite tu regardes le code qu'elle a généré. c'est bête, mais c'est la meilleur solution que je connaisse.


<HR>
Sébastien FERRAND

Blog : http://blogs.developpeur.org/sebmafate
3
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
22 août 2005 à 11:30
tout ce que tu fais "à la main" dans excel est possible avec C#.

ca répond à ta question ?


<HR>
Sébastien FERRAND

Blog : http://blogs.developpeur.org/sebmafate
0
cs_Marquo Messages postés 31 Date d'inscription vendredi 22 août 2003 Statut Membre Dernière intervention 14 octobre 2005 1
22 août 2005 à 11:40
Oui merci mais est-ce que tu connaitrais les methodes à utiliser ds ces 2 cas là ?
0
cs_Marquo Messages postés 31 Date d'inscription vendredi 22 août 2003 Statut Membre Dernière intervention 14 octobre 2005 1
22 août 2005 à 11:46
Ok merci beaucoup
0

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

Posez votre question
lm86 Messages postés 10 Date d'inscription jeudi 8 juin 2006 Statut Membre Dernière intervention 27 septembre 2006
13 juil. 2006 à 11:07
Salut.

Je reviens rapidement sur ce sujet. J'ai utilisé ta technique Sebmafate mais le problème, c'est que pour pour pouvoir, par exemple, mettre une bordure sur le coté droit d'une cellule, il faut utilisé "xlEdgeRight" et je ne sais pas où trouver cette attribut.

Voila. Si quelqu'un a une idée, ça m'arangerai en fait!!!
0
cs_Cathbad Messages postés 2 Date d'inscription jeudi 20 juillet 2006 Statut Membre Dernière intervention 24 juillet 2006
24 juil. 2006 à 14:39
Iop, J'ai le même problème que toi mais sous VB6 enfin je dois utiliser la constante xledgeright. Comme toute constante celle ci représente une valeur. Donc la solution c'est de faire un msgbox xledgeright (sous vba) et de zieuter le résultat. Ensuite tu n'as plus qu'a remplacer tes xledgeright /bottom /top .. etc par les valeurs que tu obtiendras.
0
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
24 juil. 2006 à 15:11
Vous pouvez toujours aller jeter un oeil sur ce poste.
La constante semble valoir 10.

VC# forever
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
24 juil. 2006 à 22:36
Sinon la doc ça marche pas mal aussi ^^ : [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaxl11/html/xlhowConstants_HV01049962.asp Microsoft Excel Constants [Excel 2003 VBA Language Reference]]

/*
coq
MVP Visual C#
CoqBlog
*/
0
delphi2004 Messages postés 6 Date d'inscription jeudi 26 février 2004 Statut Membre Dernière intervention 29 décembre 2008
31 mars 2010 à 22:16
krimou
HiLook into this code this might help u out.Add excel reference to the project.C# codeExcel.Application oXL = new Excel.Application(); // The excel application.


Excel.Workbook theWorkbook; // The workbook in the excel application.


Excel.Worksheet worksheet; // The worksheet in the workbook.


// Set the Excel application to visible. This is not necessary
// but makes it easier during debugging.





oXL.Visible = true;



// Open the Excel template and get the workbook in the Excel file.




theWorkbook = oXL.Workbooks.Add(Type.Missing);


if ( theWorkbook.Worksheets.Count > 0)


{


// Select the sheet that the report data will be placed on.


worksheet = (Excel.Worksheet)theWorkbook.Sheets[1];


// Activate the worksheet so that the data will show up


worksheet.Activate();


// Apply the formatting necessary for the report.


Range rg = worksheet.get_Range("A1","E1");


rg.Select();
//boldrg.Font.Bold = true;
// font facerg.Font.Name = "Arial";
//font sizerg.Font.Size = 8;
// text wraprg.WrapText = true;
// cell allignment









rg.HorizontalAlignment = Excel.Constants.xlCenter;
// color indexrg.Interior.ColorIndex = 6;
// font weightrg.Borders.Weight = 3;
// Border Line stylerg.Borders.LineStyle = Excel.Constants.xlSolid;
// row heightrg.Cells.RowHeight = 38;












rg = worksheet.get_Range("A1",Type.Missing);


rg.Cells.ColumnWidth = 7;


rg.Value2 = "Ticker";


rg = worksheet.get_Range("B1",Type.Missing);


rg.Cells.ColumnWidth = 11;


rg.Value2 = "Purchase Date";







rg = worksheet.get_Range("C1",Type.Missing);



rg.Cells.ColumnWidth = 6.5;



rg.Value2 = "Shares";







rg = worksheet.get_Range("D1",Type.Missing);



rg.Cells.ColumnWidth = 10;



rg.Value2 = "Purchase Price";







rg = worksheet.get_Range("E1",Type.Missing);



rg.Cells.ColumnWidth = 11;



rg.Value2 = "Total";



int RowCounter = 2;



double TotalValue = 0;


// Get the data from the dataset created above
// and populate the spreadsheet.





DataRow[] rpt = ACTable.Select("Ticker <> ''","Ticker ASC");



foreach(DataRow dr in rpt)



{



// Format each row of data for the report.


rg = (Excel.Range)worksheet.Rows[RowCounter, Type.Missing];


rg.HorizontalAlignment = Excel.Constants.xlCenter;


rg.Cells.RowHeight = 12;


rg.Font.Name = "Aerial";


rg.Font.Size = 8;



// Custom Cell Formatting

// Purchase Date


// Format the Purchase Date cell for a


// date time. The dataset table will return


// a date with the time.



rg = (Excel.Range)worksheet.Cells[RowCounter,2];
rg.NumberFormat = "MM/DD/YYYY";





// Purchase Price
// Format the purchase price to currency.





rg = (Excel.Range)worksheet.Cells[RowCounter,4];
rg.NumberFormat = "$0.00";





// Drop the data into the spreadsheet.



worksheet.Cells[RowCounter,1] = dr["Ticker"].ToString();


worksheet.Cells[RowCounter,2] = dr["PurchaseDate"].ToString();


worksheet.Cells[RowCounter,3] = dr["Shares"].ToString();


worksheet.Cells[RowCounter,4] = dr["PurchasePrice"].ToString();


// This is just to show that the formatting can be
// done with .NET instead of using the NumberFormat.






TotalValue = Convert.ToDouble(dr["Total"].ToString());


worksheet.Cells[RowCounter,5] = TotalValue.ToString("C");


RowCounter++;


}



// Save the workbook.
FileInfo f = new FileInfo(SavePath + @"\MyReport.xls");


if(f.Exists)


f.Delete(); // delete the file if it already exist.



oXL.ActiveWorkbook.SaveAs(SavePath + @"\MyReport",


Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing,


Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange ,


Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


oXL.Visible = false;



theWorkbook.Close(null,null,null);


oXL.Workbooks.Close();


oXL.Application.Quit();


oXL.Quit();



System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);


System.Runtime.InteropServices.Marshal.ReleaseComObject(theWorkbook);


System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL);


worksheet = null;


theWorkbook = null;


oXL = null;



return true;---------------
0
Rejoignez-nous