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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
   |  
//---------------------------------------------------------------------------
 
#include <vcl.h>
#pragma hdrstop
 
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
Variant vMSExcel, vXLWorkbooks, vXLWorkbook;
vMSExcel = Variant::CreateObject("Excel.Application");
vMSExcel.OlePropertySet("Visible", true);
Variant vFileName, vNotUsed, vSeparator, FileFormat, ReadOnlyRecommended;
Variant CreateBackup, Password, WriteResPassword;
Variant Mot_passe;
// ouverture d'un fichier au format csv
vFileName = "C:\\Documents and Settings\\blondelle\\Mes documents\\plan_gps\\PLAN_GPS\\télégraphe.csv";
vNotUsed = Unassigned;
vSeparator = 1;
vXLWorkbooks = vMSExcel.OlePropertyGet("Workbooks");
vXLWorkbook = vXLWorkbooks.OleFunction("Open", vFileName, vNotUsed,
vNotUsed, vSeparator);
//
// preparation de la sauvegarde
//
FileFormat = -4143; // valeur de xlNormal "sauvegarde sous format classeur excel"
                    // pour les autres format de sauvegarde faire un essai avec VBE
 
// creation d'un mot de passe protegeant l'ouverture du fichier
// attention si le fichier a ete sauvegarde avec un mot de passe
// il ne peut pas etre reecrit cela provoque une exception
Mot_passe = "jpb"; // pour la protection du fichier
 
Password = Mot_passe; // mot de passe pour proteger le fichier
 
WriteResPassword = Mot_passe; // confirmation du mot de passe
 
ReadOnlyRecommended = true; // fichier en lecture seule (False True Unassigned)
 
// creation d'une copie si le fichier existe deja
CreateBackup = true;  //Unassigned; // creation d'une copie (False True Unassigned)
 
// fermeture d'un fichier (ouvert au format csv) au format xls
vFileName = "C:\\Documents and Settings\\blondelle\\Mes documents\\plan_gps\\PLAN_GPS\\télégraphe.xls";
vXLWorkbook.OleProcedure("Saveas", vFileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup);
 
// fermeture d'excel
vMSExcel.OleFunction("Quit");
// liberation memoire
vMSExcel = Unassigned;
}
//---------------------------------------------------------------------------
/*
Sub Macro1()
'
' Macro1 Macro
' Macro enregistrée le 24/07/2006 par blondelle
'
 
'
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\blondelle\Mes documents\plan_gps\PLAN_GPS\télégraphe.xls" _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
*/ | 
Partager