I created a program in C # to create an Excel file containing the data of a database. As you can see in my code, I indicated the title that I wanted to have and I also specified the destination path for the Excel file that I want to create. Except that it does not work because the Excel file is not created. Can you help me please ? Thanks :)
Here is my Hand:
public static void Main(string[] args)
{
if (args.Length > 0)
{
if (args[0] == "T1" || args[0] == "T2")
{
var dossierDestination = args[1];
EnumTraitements t;
if (args[0]=="T1")
{
t = EnumTraitements.ExportNouveauxMessages;
}
else
{
t = EnumTraitements.ExportMessagesModifies;
}
SqlConnection myConnection = null;
myConnection = OuvrirBaseReferentiel();
switch (t)
{
case EnumTraitements.ExportNouveauxMessages:
List<Messages> listeNouveauxMsg;
listeNouveauxMsg = new List<Messages>();
SLDocument sl = new SLDocument();
List<Messages> listeDesMessagesVersionPrecedente = DonneMoiTousLesMessages(11, 1, "FR", myConnection);
List<Messages> listeDesMessagesVersionActuelle = DonneMoiTousLesMessages(12, 1, "FR", myConnection);
foreach (Messages msgAct in listeDesMessagesVersionActuelle)
{
bool estCeQueLeMsgExistaitDansLaVersionPrecedente = listeDesMessagesVersionPrecedente.Exists(m => m.Application == msgAct.Application && m.Langue == msgAct.Langue && m.Chapitre == msgAct.Chapitre && m.NumeroMessage == msgAct.NumeroMessage);
if (estCeQueLeMsgExistaitDansLaVersionPrecedente == true)
{
listeNouveauxMsg.Add(msgAct);
}
}
sl = new SLDocument();
EcireLigneTitreExcel_NouveauxMessages(sl);
int i = 1;
foreach (Messages m in listeNouveauxMsg)
{
CreerLigneExcelNouveauxMsg(m, sl, i);
}
sl.SaveAs(dossierDestination);
break;
case EnumTraitements.ExportMessagesModifies:
List<Messages> listeDesMessagesVersionPrecedentee = DonneMoiTousLesMessages(11, 1, "FR", myConnection);
List<Messages> listeDesMessagesVersionActuellee = DonneMoiTousLesMessages(12, 1, "FR", myConnection);
List<Messages> listeMsgModifies;
listeMsgModifies = new List<Messages>();
foreach (Messages msgAct in listeDesMessagesVersionActuellee)
{
bool estCeQueLeLibelleAChange = listeDesMessagesVersionPrecedentee.Exists(m => m.Libelle != msgAct.Libelle &&
m.Application == msgAct.Application && m.Langue == msgAct.Langue && m.Chapitre == msgAct.Chapitre && m.NumeroMessage == msgAct.NumeroMessage);
if (estCeQueLeLibelleAChange == true)
{
Messages msgMessage = listeDesMessagesVersionPrecedentee.Find(m => m.Application == msgAct.Application && m.Langue == msgAct.Langue && m.Chapitre == msgAct.Chapitre && m.NumeroMessage == msgAct.NumeroMessage);
msgAct.LibelleAvant = msgMessage.Libelle;
listeMsgModifies.Add(msgAct);
}
}
SLDocument sl2 = new SLDocument();
EcrireLigneTitreExcel_MessagesModifies(sl2);
int j = 1;
foreach (Messages m in listeMsgModifies)
{
CreerLigneExcelMsgModifies(m, sl2, j);
}
string annee = DateTime.Now.Year.ToString("0000");
string mois = DateTime.Now.Month.ToString("00");
string day = DateTime.Now.Day.ToString("00");
string hour = DateTime.Now.Hour.ToString("00");
string minute = DateTime.Now.Minute.ToString("00");
string testDateHeureCOuranteConvertieEnstring = "EN_NEW_MSG_OM" + annee + mois + day + hour + minute+ ".xlsx";
sl2.SaveAs(testDateHeureCOuranteConvertieEnstring);
break;
}
FermerBaseReferentiel(myConnection);
}
}
}
}
}