コード例 #1
0
        private void GenererTableau(ref ExcelSDK.Worksheet feuille, Tableau tableau)
        {
            ExcelSDK.Range cellules = null;
            Table          donnees  = tableau.Donnees;
            int            nbChamps = donnees.EstVide ? 1 : donnees.NombreChampsParLigne;

            try
            {
                noColonne = 0;

                int noPremiereLigne = noLigne;

                string nomCellule1 = GetNomColonne(noColonne) + noLigne.ToString();
                string nomCellule2 = GetNomColonne(nbChamps - 1) + noLigne.ToString();

                foreach (string titre in tableau.Titres)
                {
                    cellules = feuille.get_Range(nomCellule1, nomCellule2);
                    cellules.Merge();
                    cellules.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                    cellules.Value     = titre;
                    cellules.Font.Bold = true;

                    ++noLigne;

                    nomCellule1 = GetNomColonne(noColonne) + noLigne.ToString();
                    nomCellule2 = GetNomColonne(nbChamps - 1) + noLigne.ToString();
                }

                if (!donnees.EstVide)
                {
                    foreach (Champ c in donnees.Lignes[0].Champs)
                    {
                        nomCellule1 = GetNomColonne(noColonne) + noLigne.ToString();
                        cellules    = feuille.get_Range(nomCellule1);

                        string nom = c.NomEntete;
                        cellules.Value = (nom == null || nom == "") ? c.Nom : nom;

                        cellules.Font.Bold = true;
                        ++noColonne;
                    }

                    foreach (LigneTable ligne in donnees.Lignes)
                    {
                        ++noLigne;
                        noColonne = 0;

                        foreach (Champ c in ligne.Champs)
                        {
                            nomCellule1    = GetNomColonne(noColonne) + noLigne.ToString();
                            cellules       = feuille.get_Range(nomCellule1);
                            cellules.Value = c.ValeurExcel;

                            ++noColonne;
                        }
                    }
                }

                if (tableau.HauteurLignes > 0)
                {
                    nomCellule1        = GetNomColonne(0) + noPremiereLigne.ToString();
                    nomCellule2        = GetNomColonne(nbChamps - 1) + noLigne.ToString();
                    cellules           = feuille.get_Range(nomCellule1, nomCellule2);
                    cellules.RowHeight = tableau.HauteurLignes;
                }

                nomCellule1 = GetNomColonne(0) + noPremiereLigne.ToString();
                nomCellule2 = GetNomColonne(nbChamps - 1) + noLigne.ToString();

                cellules = feuille.get_Range(nomCellule1, nomCellule2);
                cellules.Borders.LineStyle = ExcelSDK.XlLineStyle.xlContinuous;
                cellules.Borders.Weight    = 2;
                cellules.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;

                if (tableau.GrosseurPolice > 0 && tableau.GrosseurPolice < 410)
                {
                    cellules.Font.Size = tableau.GrosseurPolice;
                }

                noLigne += 2;
            }
            catch (Exception ex)
            {
                Journal.EcrireException("Erreur Excel", ex);
            }
            finally
            {
                if (cellules != null)
                {
                    Marshal.ReleaseComObject(cellules);
                }
            }
        }
コード例 #2
0
 public void AjouterTableau(Tableau tableau)
 {
     Tableaux.Add(tableau);
 }