//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Word_XP_srvr" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- // Julian century depuis 01/01/2000 à 12h UT double JulianCentury (int date, int month, int year, double UT) { if (month<=2) {month=month+12; year=year-1;} return ((int)(365.25*year) + (int)(30.6001*(month+1)) - 15 + 1720996.5 + date + UT/24.0 - 2451545.0)/36525.0; } //--------------------------------------------------------------------------- int CalculeNjdumois(int m, int annee) { int Nonbissextile=(annee-4*(int)(annee/4)+2)/3; // 1 pour une année commune et 0 pour une bissextile) if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) return 31; else { if (m==2) {if (Nonbissextile) return 28; else return 29; } else return 30; } } //--------------------------------------------------------------------------- int CalculeJour(double T) // à pertir du siecle Julien { double jour=T*36525+5; return jour-7*(int)(jour/7); } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Mounths[0]="Janvier"; Mounths[1]="Février"; Mounths[2]="Mars"; Mounths[3]="Avril"; Mounths[4]="Mai"; Mounths[5]="Juin"; Mounths[6]="Juillet"; Mounths[7]="Août"; Mounths[8]="Septembre"; Mounths[9]= "Octobre"; Mounths[10]="Novembre"; Mounths[11]="Décembre"; Days[0]="Lundi"; Days[1]="Mardi"; Days[2]="Mercredi"; Days[3]="Jeudi"; Days[4]="Vendredi"; Days[5]="Samedi"; Days[6]="Dimanche"; for (int i=1950; i<2050; i++) CBAnnee->Items->Add(i); CBAnnee->ItemIndex=2007-1950; // place la sélection sur 2007 !!! } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonGenereClick(TObject *Sender) { int annee, mois, jour; double T; // Siecle Julien : T, int erreur, Nj[12], IndexM[12], stdcolor, C ,i; double ratio; int daysAnnuel[12][31]; AnsiString FileName, FilePath; Table * Table1; //OleVariant Template, AsModel; annee=CBAnnee->ItemIndex+1950; for (mois=1; mois<=12; mois++) { Nj[mois-1]=CalculeNjdumois( mois, annee); for (jour=1; jour<=Nj[mois-1];jour++) { T=JulianCentury (jour, mois, annee, 12); // pour 12h // daysAnnuel[mois-1][jour-1]=CalculeJour((T)/24.0/36525.0); // juste pour le jour (Lundi, mardi...) daysAnnuel[mois-1][jour-1]=CalculeJour(T+(1+12)/24.0/36525.0); // juste pour le jour (Lundi, mardi...) 1 : Time Zone } } // Cree un fichier Word FilePath=ExtractFilePath(Application->ExeName); FileName=FilePath+"Calendrier_"+AnsiString(annee)+".doc"; // Lance Word ou se connecte à un word existant WordApplication1->Connect(); WordApplication1->Visible=true; // Cree un fichier Word WordDocument1-> Connect(); // ou alors WordDocument1-> ConnectTo(WordApplication1->Documents->AddOld( Template, AsModel)); // utilise le template WordDocument1->SaveAs( (Variant)WideString(FileName)); // ici on sauve un document // on prepare la Font du texte WordApplication1->Selection->ParagraphFormat->Alignment=wdAlignParagraphCenter; WordApplication1->Selection->Font->Name=WideString("Verdana"); WordApplication1->Selection->Font->Size=20; // on insere du texte WordApplication1->Selection->TypeText(WideString("Calendrier" + IntToStr(annee))); // on fait un passage a la ligne suivante WordApplication1->Selection->TypeParagraph(); WordApplication1->Selection->Font->Size=8; WordApplication1->Selection->TypeText(WideString("Generated by Lotfi ©")); WordApplication1->Selection->TypeParagraph(); WordApplication1->Selection->TypeParagraph(); WordApplication1->Selection->TypeParagraph(); InlineShape * Shape=WordApplication1->Selection->InlineShapes->AddPicture( WideString(FilePath+"3.jpg"), (OleVariant)false, (OleVariant)true, EmptyParam); Shape->LockAspectRatio = msoTrue; if (Shape->Height!=0) ratio=200.0/Shape->Height; else ratio=1; Shape->Height *=ratio; Shape->Width *=ratio; WordApplication1->Selection->TypeParagraph(); WordApplication1->Selection->TypeText(WideString("El masdjed ennabawi, el Madina el mounawara")); WordApplication1->Selection->TypeParagraph(); WordApplication1->Selection->TypeParagraph(); // table du calendrier for (i=0; i<4; i++) // crée en 4 tables de 3 colonnes { // on insere un tableau 8 lignes 24 colonnes Table1=WordDocument1->Tables->AddOld( WordApplication1->Selection->Range, 8, 24); Table1->Rows->SetLeftIndent( 12.5, wdAdjustNone); // Bold et couleur l'intitulé des mois et jours: //// Table1.OlePropertyGet("Rows").OleFunction("Item", "1").OleFunction("Select"); //// vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Color",wdColorDarkTeal); Table1->Rows->Item(1)->Select(); WordApplication1->Selection->Font->Color=wdColorDarkBlue; // idem de MyRange->SetRange( Table1->Rows->Item(1)->Range->Start, Table1->Rows->Item(1)->Range->End); // MyRange->Font->Color=wdColorDarkBlue; Table1->Rows->Item(1)->Select(); WordApplication1->Selection->Font->Bold=true; WordApplication1->Selection->MoveDown( (OleVariant)wdLine, (OleVariant)1, (OleVariant)wdExtend); WordApplication1->Selection->Font->Bold=true; // idem de MyRange->SetRange( Table1->Rows->Item(1)->Range->Start, Table1->Rows->Item(2)->Range->End); //// MyRange = WordDocument1->OleFunction("Range", Table1.²OlePropertyGet("Rows").OleFunction("Item", "1").OlePropertyGet("Range").OlePropertyGet("Start"), //// Table1.OlePropertyGet("Rows").OleFunction("Item", "2").OlePropertyGet("Range").OlePropertyGet("End")); // MyRange->Font->Bold=true; for (mois=1+3*i; mois<=3+3*i; mois++) // entete des mois { C=8*(mois-1-3*i)+1; IndexM[mois-1]=1; // debut du mois Table1->Cell(1,C)->Range->InsertAfter( WideString(Mounths[mois-1].c_str()+AnsiString(" ")+annee)); Table1->Cell(2,C+0)->Range->InsertAfter(WideString("L")); Table1->Cell(2,C+1)->Range->InsertAfter(WideString("M")); Table1->Cell(2,C+2)->Range->InsertAfter(WideString("M")); Table1->Cell(2,C+3)->Range->InsertAfter(WideString("J")); Table1->Cell(2,C+4)->Range->InsertAfter(WideString("V")); Table1->Cell(2,C+5)->Range->InsertAfter(WideString("S")); Table1->Cell(2,C+6)->Range->InsertAfter(WideString("D")); for (int semaine=0; semaine<6; semaine++) for (int JourSemaine=0; JourSemaine<7; JourSemaine++) { if ( (JourSemaine >= daysAnnuel[mois-1][IndexM[mois-1]-1] || IndexM[mois-1]!=1) && IndexM[mois-1] <= Nj[mois-1] ) { Table1->Cell(3+semaine,C+JourSemaine)->Range->InsertAfter(WideString( IndexM[mois-1])); // Table1.OleFunction( "Cell", 3+semaine, C+JourSemaine ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", IndexM[mois-1]); IndexM[mois-1]++; } } // colore la colonne vendredi et dimanche Table1->Cell(2,C+4)->Select(); WordApplication1->Selection->MoveDown( (OleVariant)wdLine, (OleVariant)5, (OleVariant)wdExtend); WordApplication1->Selection->Font->Color=wdColorBlue; Table1->Cell(2,C+6)->Select(); WordApplication1->Selection->MoveDown( (OleVariant)wdLine, (OleVariant)5, (OleVariant)wdExtend); WordApplication1->Selection->Font->Color=wdColorRed; } //for (mois=1+3*i... // fusionne l'intitulé des mois : Table1->Cell(1,1)->Merge( Table1->Cell(1, 7)); Table1->Cell(1,3)->Merge( Table1->Cell(1, 9)); Table1->Cell(1,5)->Merge( Table1->Cell(1, 11)); // atteint la fin du fichier WordApplication1->Selection->EndKey((OleVariant)wdStory, (OleVariant)wdMove); WordApplication1->Selection->TypeParagraph(); WordApplication1->Selection->TypeParagraph(); } //for (int i=0; i<4; i++) WordDocument1->Save(); // ici on sauve un document if (Application->MessageBoxA("Cliquez pour fermer", "Debug", MB_YESNO)==IDYES) WordDocument1->Close(); // on ferme le document // WordApplication1->Quit(); // on ferme Word //--------------------------------------------------------------------------- } |
//--------------------------------------------------------------------------- void __fastcall TForm1::ButtonGenereClick(TObject *Sender) { int annee, mois, jour; double T; // Siecle Julien : T, int erreur, Nj[12], IndexM[12], stdcolor, C ,i; double Height, Width, ratio; int daysAnnuel[12][31]; AnsiString FileName, FilePath; Variant vMSWord, vWDocument, vWDocuments, Table1, MyRange; //OleVariant Template, AsModel; annee=CBAnnee->ItemIndex+1950; for (mois=1; mois<=12; mois++) { Nj[mois-1]=CalculeNjdumois( mois, annee); for (jour=1; jour<=Nj[mois-1];jour++) { T=JulianCentury (jour, mois, annee, 12); // pour 12h // daysAnnuel[mois-1][jour-1]=CalculeJour((T)/24.0/36525.0); // juste pour le jour (Lundi, mardi...) daysAnnuel[mois-1][jour-1]=CalculeJour(T+(1+12)/24.0/36525.0); // juste pour le jour (Lundi, mardi...) 1 : Time Zone } } // Cree un fichier Word FilePath=ExtractFilePath(Application->ExeName); FileName=FilePath+"Calendrier_"+AnsiString(annee)+"_oleVariant.doc"; // Lance Word ou se connecte à un word existant try { vMSWord = Variant::GetActiveObject("Word.Application"); } catch(...) { vMSWord = Variant::CreateObject("Word.Application"); } vMSWord.OlePropertySet("Visible", true); // cree un nouveau doc vWDocuments = vMSWord.OlePropertyGet("Documents"); vWDocument = vWDocuments.OleFunction("Add"); vWDocument.OleProcedure("Saveas", FileName.c_str()); // ici on sauve un document // on prepare la Font du texte vMSWord.OlePropertyGet("Selection").OlePropertyGet("ParagraphFormat").OlePropertySet("Alignment", wdAlignParagraphCenter); vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Name", "Verdana"); vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Size", "20"); // on insere du texte vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText", WideString("Calendrier" + IntToStr(annee))); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Size", "8"); vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText", "Generated by Lotfi (c)"); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); Variant Shape=vMSWord.OlePropertyGet("Selection").OlePropertyGet("InlineShapes").OleFunction("AddPicture", WideString(FilePath+"3.jpg"), false, true); Shape.OlePropertySet("LockAspectRatio", msoTrue); // msoTrue Height=Shape.OlePropertyGet("Height"); Width=Shape.OlePropertyGet("Width"); if (Height!=0) ratio=200.0/Height; else ratio=1; Height *=ratio; Width *=ratio; Shape.OlePropertySet("Height", Height); Shape.OlePropertySet("Width", Width); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText", "El masdjed ennabawi, el Madina el mounawara"); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); // table du calendrier for (i=0; i<4; i++) // crée en 4 tables de 3 colonnes { // on insere un tableau 8 lignes 24 colonnes vWDocument.OlePropertyGet("Tables").\ OleFunction("Add", vMSWord.OlePropertyGet("Selection").OlePropertyGet("Range"), 8, 24); Table1 = vWDocument.OlePropertyGet("Tables").OleFunction( "Item", i+1 ); //debug // Table1->Rows->SetLeftIndent( 12.5, wdAdjustNone); Table1.OlePropertyGet("Rows").OleFunction("SetLeftIndent", "0", wdAdjustNone); // Bold et couleur l'intitulé des mois et jours: //// Table1.OlePropertyGet("Rows").OleFunction("Item", "1").OleFunction("Select"); //// vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Color",wdColorDarkTeal); MyRange = vWDocument.OleFunction("Range", Table1.OlePropertyGet("Rows").OleFunction("Item", "1").OlePropertyGet("Range").OlePropertyGet("Start"), Table1.OlePropertyGet("Rows").OleFunction("Item", "2").OlePropertyGet("Range").OlePropertyGet("End")); MyRange.OlePropertyGet("Font").OlePropertySet("Color", wdColorDarkBlue); MyRange = vWDocument.OleFunction("Range", Table1.OlePropertyGet("Rows").OleFunction("Item", "1").OlePropertyGet("Range").OlePropertyGet("Start"), Table1.OlePropertyGet("Rows").OleFunction("Item", "2").OlePropertyGet("Range").OlePropertyGet("End")); MyRange.OlePropertyGet("Font").OlePropertySet("Bold",true); for (mois=1+3*i; mois<=3+3*i; mois++) // entete des mois { C=8*(mois-1-3*i)+1; IndexM[mois-1]=1; // debut du mois Table1.OleFunction( "Cell", 1, C).OlePropertyGet( "Range" ).\ OleFunction("InsertAfter", StringToOleStr(WideString(Mounths[mois-1].c_str()+AnsiString(" ")+annee))); Table1.OleFunction( "Cell", 2, C+0 ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", "L"); Table1.OleFunction( "Cell", 2, C+1 ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", "M"); Table1.OleFunction( "Cell", 2, C+2 ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", "M"); Table1.OleFunction( "Cell", 2, C+3 ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", "J"); Table1.OleFunction( "Cell", 2, C+4 ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", "V"); Table1.OleFunction( "Cell", 2, C+5 ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", "S"); Table1.OleFunction( "Cell", 2, C+6 ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", "D"); for (int semaine=0; semaine<6; semaine++) for (int JourSemaine=0; JourSemaine<7; JourSemaine++) { if ( (JourSemaine >= daysAnnuel[mois-1][IndexM[mois-1]-1] || IndexM[mois-1]!=1) && IndexM[mois-1] <= Nj[mois-1] ) { Table1.OleFunction( "Cell", 3+semaine, C+JourSemaine ).OlePropertyGet( "Range" ).OleFunction("InsertAfter", IndexM[mois-1]); IndexM[mois-1]++; } } // colore la colonne vendredi et dimanche Table1.OleFunction("Cell", 2, C+4).OleFunction("Select"); vMSWord.OlePropertyGet("Selection").OleFunction("MoveDown", wdLine, 5, wdExtend); vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Color", wdColorBlue); Table1.OleFunction("Cell", 2, C+6).OleFunction("Select"); vMSWord.OlePropertyGet("Selection").OleFunction("MoveDown", wdLine, 5, wdExtend); vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Color", wdColorRed); } //for (mois=1+3*i... // fusionne l'intitulé des mois : MyRange = vWDocument.OleFunction("Range", Table1.OleFunction("Cell", 1, 1).OlePropertyGet("Range").OlePropertyGet("Start"), Table1.OleFunction("Cell", 1, 7).OlePropertyGet("Range").OlePropertyGet("End")); MyRange.OlePropertyGet("Cells").OleProcedure("Merge"); MyRange = vWDocument.OleFunction("Range", Table1.OleFunction("Cell", 1, 3).OlePropertyGet("Range").OlePropertyGet("Start"), Table1.OleFunction("Cell", 1, 9).OlePropertyGet("Range").OlePropertyGet("End")); MyRange.OlePropertyGet("Cells").OleProcedure("Merge"); MyRange = vWDocument.OleFunction("Range", Table1.OleFunction("Cell", 1, 5).OlePropertyGet("Range").OlePropertyGet("Start"), Table1.OleFunction("Cell", 1, 11).OlePropertyGet("Range").OlePropertyGet("End")); MyRange.OlePropertyGet("Cells").OleProcedure("Merge"); // atteint la fin du fichier vMSWord.OlePropertyGet("Selection").OleProcedure("EndKey", "6"); vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph"); } //for (int i=0; i<4; i++) vWDocument.OleProcedure("Save"); // ici on sauve un document if (Application->MessageBoxA("Cliquez pour fermer", "Debug", MB_YESNO)==IDYES) vWDocument.OleFunction("Close"); // on ferme le document // vMSWord.OleFunction("Quit"); // on ferme Word vMSWord = Unassigned; // on libere les Variants //--------------------------------------------------------------------------- } |
Ligne vide | Ligne vide | Ligne vide | Ligne vide | Ligne vide | Ligne vide |
username | password | idnumber | Nom | Prénom | |
marc1 | marc1pw1 | 1 | Dupont | Marc | marc.dupont@landtoto.fr |
yves2 | yves2pw2 | 2 | Durand | Yves | yves.Durand@totoland.fr |
... | ... | ... | ... | ... | ... |
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Excel_XP_srvr" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { IdSMTP1->Host = "smtp.free.fr"; IdSMTP1->Username = "toto"; IdSMTP1->Password = ""; IdMessage1->From->Name = "webmaster"; IdMessage1->From->Address = "toto@free.fr"; IdMessage1->Subject = "Toto forum loggin"; IdMessage1->ContentType = "multipart/alternative"; //Message 'découpé' en plusieurs parties } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonOpenFichierClick(TObject *Sender) { OpenDialogFichier->Execute(); if (OpenDialogFichier->FileName!="") { EditFichier->Text=OpenDialogFichier->FileName; OKBtn->Enabled=true; } } //--------------------------------------------------------------------------- void __fastcall TForm1::OKBtnClick(TObject *Sender) { int debut=3; ExcelRange * myrange; OleVariant Range; AnsiString myusername, mypw, myemail; if (CBemailaussi->Checked) { if (IdSMTP1->Password==""){ MessageDlg("PassWord vide", mtInformation, TMsgDlgButtons() << mbOK, 0); return; } try { IdSMTP1->Connect(); } catch(const Exception& e) { MessageDlg("erreur d'envoi" /*e.what()*/, mtInformation, TMsgDlgButtons() << mbOK, 0); Memo1->Lines->Add( "Connexion au SMTP échouée"); return; } } ExcelApplication1->Connect(); ExcelApplication1->set_Visible(true,true); AnsiString FileName=EditFichier->Text; AnsiString FeuilleName=(RDFeuille->ItemIndex==0 ? "inscrits 1A" : "inscrits 2A"); ExcelWorkbook1->ConnectTo(ExcelApplication1->Workbooks->Open( WideString(FileName))); ExcelWorksheet1->ConnectTo(ExcelApplication1->Worksheets->get_Item(TVariant(FeuilleName))); do{ Range="A"+IntToStr(debut); myrange=ExcelWorksheet1->get_Range(Range,Range); myusername= (String)((TVariant)myrange->get_FormulaR1C1()); if ( myusername=="" || debut>500) break; Range="B"+IntToStr(debut); myrange=ExcelWorksheet1->get_Range(Range,Range); mypw= (String)((TVariant)myrange->get_FormulaR1C1()); Range="F"+IntToStr(debut); myrange=ExcelWorksheet1->get_Range(Range,Range); myemail= (String)((TVariant)myrange->get_FormulaR1C1()); Memo1->Lines->Add( myusername +" "+ mypw +" "+myemail); //envoi le mail if (CBemailaussi->Checked) { IdMessage1->Recipients->EMailAddresses = myemail; IdMessage1->Body->Clear(); IdMessage1->Body->Add("Bienvenu sur le forum de Toto" ); IdMessage1->Body->Add("Votre login est : "+myusername ); IdMessage1->Body->Add("Votre mot de passe est : "+mypw ); try { IdSMTP1->Send(IdMessage1); } catch(...) { // MessageDlg("erreur d'envoi" /*e.what()*/, mtInformation, TMsgDlgButtons() << mbOK, 0); Memo1->Lines->Add( "envoi de mail de : "+myusername ); } } debut++; } while(1); // fin de la boucle Memo1->Lines->Add( "Traitement xls ok"); if (CBemailaussi->Checked) { Memo1->Lines->Add( "envoi de mail ok"); try { IdSMTP1->Disconnect(); } catch(...) { Memo1->Lines->Add( "Deconnexion du SMTP échouée"); } } } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonOptionsClick(TObject *Sender) { FormOptions->EdHost->Text=IdSMTP1->Host; FormOptions->EdUserId->Text=IdSMTP1->Username; FormOptions->EdPassword->Text=IdSMTP1->Password; FormOptions->EdName->Text=IdMessage1->From->Name; FormOptions->EdAddress->Text=IdMessage1->From->Address; FormOptions->EdSubject->Text=IdMessage1->Subject; if (FormOptions->ShowModal()==ID_OK) { IdSMTP1->Host=FormOptions->EdHost->Text; IdSMTP1->Username=FormOptions->EdUserId->Text; IdSMTP1->Password=FormOptions->EdPassword->Text; IdMessage1->From->Name=FormOptions->EdName->Text; IdMessage1->From->Address=FormOptions->EdAddress->Text; IdMessage1->Subject=FormOptions->EdSubject->Text; } } //--------------------------------------------------------------------------- |