1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| private void CreerListeExcel()
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = true;
//Get a new workbook.
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
// Create an array to multiple values at once.
string[,] saNames = new string[m_nbElem+1,2];
int Ligne = 0;
// Pour chaque Email de la chaine, l'ajouter au tableau pour l'ajout
// dans un fichier excel.
while( m_Destinataire.IndexOf(";") != -1 )
{
saNames[ Ligne, 0] = m_Destinataire.Substring(0,(m_Destinataire.IndexOf(";")));
// Supprimer le courriel
m_Destinataire = m_Destinataire.Remove(0,m_Destinataire.IndexOf(";")+1);
Ligne++;
}
Ligne++;
// Determine la case Final du range
string nbElem = "A" + Ligne.ToString();
// Pour un range donnée affecté les valeur du tableau de courriel
oSheet.get_Range("A1",nbElem).Value2 = saNames;
}
catch (System.Exception ex)
{
string bob = ex.Message.ToString();
}
} |
Partager