IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Modules Perl Discussion :

win32::ole tableau dynamique excel - suppression du soustotal


Sujet :

Modules Perl

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Septembre 2008
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 2
    Points : 1
    Points
    1
    Par défaut win32::ole tableau dynamique excel - suppression du soustotal
    J'écris prog Perl pour automatiser la creation d'un fichier excel à partir de données provenant de diverses sources.

    Je réalise un tableau croisé dynamique.
    j'essaie de supprimer les soustotaux mais cela retourne une erreur.
    Can't modify non-lvalue subroutine call at testexcel.pl line 52.
    Le code est ci dessous - petit exemple.
    La macro2 en VBA marche....

    Je n'arrive pas à trouver ce qui coince.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    #!/usr/bin/perl
     
    use Win32::OLE;
    use Win32::OLE::Const 'Microsoft Excel';
    use constant True  => 1;
    use constant False => 0;
     
    # Start Excel and make it visible
    #  $xlApp = Win32::OLE->new('Excel.Application');
    my $xlApp = Win32::OLE->GetActiveObject('Excel.Application');
    unless($xlApp)
    {
      $xlApp = new Win32::OLE('Excel.Application', \&QuitApp)
                   or die "Could not create Excel Application object";
    }
    sub QuitApp
    {
        my ($object) = @_;
        $object->Quit();
    }
    $xlApp->{Visible} = 1;
     
    # Create a new workbook
    $xlBook = $xlApp->Workbooks->Add;
     
    # Our data that we will add to the workbook...
    $mydata = [["Item",     "Category", "Price"],
               ["Nails",    "Hardware",  "5,25"],
               ["Shirt",    "Clothing", "23,00"],
               ["Hammer",   "Hardware", "16,25"],
               ["Sandwich", "Food",      "5,00"],
               ["Pants",    "Clothing", "31,00"],
               ["Drinks",   "Food",      "2,25"]];
     
    # Write all the data at once...
    $rng = $xlBook->ActiveSheet->Range("A1:C7");
    $rng->{Value} = $mydata;
     
    # Create a PivotTable for the data...
    $tbl = $xlBook->ActiveSheet->PivotTableWizard(1, $rng, "", "MyPivotTable");
    $tbl->{ManualUpdate} = True;
     
    # Set pivot fields...
    $tbl->AddDataField ( $tbl->PivotFields("Price"), "XPrice", xlSum);
    $tbl->AddFields ( { RowFields => ['Category', 'Item'] });
    $tbl->PivotFields("XPrice")->{NumberFormat}   = "# ##0,00";
    $tbl->PivotFields("Category")->{Orientation} = xlRowField;
    $tbl->PivotFields("Category")->{Position}    = 1;
    $tbl->PivotFields("Item")->{Orientation}     = xlRowField;
    $tbl->PivotFields("Item")->{Position}        = 2;
     
    $tbl->PivotFields("Item")->Subtotals(1)      = False;
     
    #Sub Macro2()
    #    ActiveSheet.PivotTables("MyPivotTable").PivotFields("Item").Subtotals(1) = False
    #End Sub
     
    $tbl->{ManualUpdate} = False;
    $tbl->{ManualUpdate} = True;
    $tbl->PivotCache->Refresh;

  2. #2
    Nouveau Candidat au Club
    Inscrit en
    Septembre 2008
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Bonjour,

    j'ai contourné le pb en créant une macro VBA.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    my $Code = q{
    Sub RemoveSubTotals ()
        ActiveSheet.PivotTables("MyPivotTable").PivotFields("Item").Subtotals(Index:=1) = False
        ActiveSheet.PivotTables("MyPivotTable").PivotFields("Category").Subtotals(Index:=1) = False
    End Sub
    };
     
    my $x = $xlBook->VBProject->VBComponents->Item(1)->CodeModule->AddFromString ( $Code );
     my $CodeName  = $xlBook->VBProject->VBComponents->Item(1)->{Name};
    $xlApp->Run ("$CodeName.RemoveSubTotals");
    Je souhaiterais ne pas utiliser une macro VBA dans mon code perl.

    Merci.

Discussions similaires

  1. [XL-2007] Tableau dynamique excel
    Par luthin dans le forum Conception
    Réponses: 10
    Dernier message: 22/11/2013, 11h09
  2. Tableau dynamique croisé: suppression de total de sous-colonne
    Par GodGives dans le forum SAP Crystal Reports
    Réponses: 4
    Dernier message: 14/01/2009, 16h21
  3. Tableau dynamique excel
    Par zizou771 dans le forum Excel
    Réponses: 1
    Dernier message: 30/04/2008, 19h29
  4. Win32::OLE::Const 'Microsoft Excel';
    Par best94 dans le forum Modules
    Réponses: 0
    Dernier message: 09/04/2008, 15h29
  5. tableau dynamique excel crée avec une macro
    Par alex_95 dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 20/03/2006, 12h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo