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 45 46 47 48 49 50 51 52 53
|
vMSWord = Variant::CreateObject("Word.Application");
vMSWord.OlePropertySet("Visible", true);
try
{
vMSWord = Variant::GetActiveObject("Word.Application");
} catch(...)
{
vMSWord = Variant::CreateObject("Word.Application");
}
vWDocuments = vMSWord.OlePropertyGet("Documents");
// ici on ouvre le document avec une feuille vierge
//vWDocument = vWDocuments.OleFunction("Add");
//
vFileName = "c:\\test_word.doc"; // date , book1
vLink = Unassigned;
vReadOnly = false; // lecture seule
vFormat = Unassigned;
vReadPass = "MotDePasse"; // mot de passe du document
vWDocuments = vMSWord.OlePropertyGet("Documents");
// ici on charge un document sur la feuille
vWDocument = vWDocuments.OleFunction("Open", vFileName, vLink, vReadOnly, vFormat, vReadPass);
// on prepare la Font du texte
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Name", "Arial");
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Size", "8");
// on insere du texte
vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText", "insertion de texte");
vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText", "insertion de texte1");
vMSWord.OlePropertyGet("Selection").OleProcedure("TypeText", "insertion de texte2");
// on fait un passage a la ligne suivante
vMSWord.OlePropertyGet("Selection").OleFunction("TypeParagraph");
// on insere un tableau deux lignes six colonnes
vWDocument.OlePropertyGet("Tables").OleFunction("Add", vMSWord.OlePropertyGet("Selection").OlePropertyGet("Range"), 2, 6);
// on selectionne tout le tableau
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Tables").OleFunction("Item", "1").OleProcedure("Select");
// on prepare la Font du tableau
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Name", "wingdings 3");
vMSWord.OlePropertyGet("Selection").OlePropertyGet("Font").OlePropertySet("Size", "18");
//----------------------------------
//----------------------------------
// on ferme Word
// on ferme le document
vWDocuments.OleFunction("Close");
// on ferme Word
vMSWord.OleFunction("Quit");
// on libere les Variants
vMSWord = Unassigned; |
Partager