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

MATLAB Discussion :

[actxserver][Excel] Je veux connaitre la dernière cellule de ma feuille excel


Sujet :

MATLAB

  1. #1
    Membre expérimenté Avatar de LordPeterPan2
    Inscrit en
    Février 2007
    Messages
    247
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 247
    Par défaut [actxserver][Excel] Je veux connaitre la dernière cellule de ma feuille excel
    Bonjour, je chercher désespéremment à faire comprendre à matlab que je veux aller à la dernière cellule de ma feuille excel :
    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
     
    [filename, pathname, filterindex] = uiputfile('*.xls', 'Pick an XLS File');
    true_filename = [pathname filesep filename] ;
     
    objExcel = actxserver( 'Excel.Application' );
     
    if exist(true_filename,'file')
        myWorkbook = invoke(objExcel.Workbooks, 'open', true_filename);
        mode_create = 0 ;
    else
        objWorkbooks = objExcel.Workbooks ;
        myWorkbook = invoke( objWorkbooks, 'Add' );
        mode_create = 1 ;
     
    end;
     
    mySheets = objExcel.ActiveWorkBook.Sheets ;
     
    myCurrentSheet = get(mySheets,'Item',get(mySheets,'Count'));
    myCells = myCurrentSheet.Cells;
    invoke(myCells,'SpecialCells','xlLastCell') % et là c'est drame :o
    Je sais que je dois appeler la méthode SpecialCell, je sais que la dernière cellule c'est xlLastCell (ce n'est pas une variable matlab vu que j'essaie justement de savoir le nom de cet <censured> de cellule).


    En fait je veux faire un programme qui va écrire dans une feuille excel plusieurs données formatées (texte + data). La feuille excel peut ne pas exister, mais si elle existe alors je veux rajouter mes données à la fin de la feuille et pas réécraser ce qui existe déjà

    A votre bon coeur m'sieur dame

  2. #2
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 317
    Par défaut
    Je n'ai pas testé mais en cherchant dans le code de XLSREAD, j'ai trouvé ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DataRange = Excel.ActiveSheet.UsedRange;
    Dans ton cas, ce serait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DataRange = myCurrentSheet.UsedRange
    Je ne sais pas ce que ça renvoie, mais je pense qu'il doit être possible de déterminer ce que tu cherches à partir de DataRange, non ?

  3. #3
    Membre expérimenté Avatar de LordPeterPan2
    Inscrit en
    Février 2007
    Messages
    247
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 247
    Par défaut
    Je te remercie Dut, mais en fait, c'est toujours le même problème j'ai tous les argument mais pas la moindre diée de la synthaxe.

    De plus, j'ai décidé de jouer le conan le barbare :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    nRow = size(myCurrentSheet.UsedRange.Formula,1)+1;

  4. #4
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 317
    Par défaut
    Tu peux me dire ce que contient ActiveSheet.UsedRange ?

    DataRange serait de quel type et contiendrait quoi ?

  5. #5
    Membre expérimenté Avatar de LordPeterPan2
    Inscrit en
    Février 2007
    Messages
    247
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 247
    Par défaut
    Alors :
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
     
    get(myCurrentSheet.UsedRange)
                Application: [1x1 Interface.Microsoft_Excel_11.0_Object_Library._Application]
                    Creator: 'xlCreatorCode'
                     Parent: [1x1 Interface.Microsoft_Excel_11.0_Object_Library._Worksheet]
                  AddIndent: 0
                    Address: '$A$1:$BW$49'
               AddressLocal: '$A$1:$BW$49'
                      Areas: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Areas]
                    Borders: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Borders]
                      Cells: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                 Characters: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Characters]
                     Column: 1
                    Columns: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                ColumnWidth: 10.7100
                      Count: 3675
               CurrentArray: [1x202 char]
              CurrentRegion: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                 Dependents: [1x202 char]
           DirectDependents: [1x202 char]
           DirectPrecedents: [1x202 char]
               EntireColumn: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                  EntireRow: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                       Font: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Font]
                    Formula: {49x75 cell}
               FormulaArray: NaN
               FormulaLabel: 'xlNoLabels'
              FormulaHidden: 0
               FormulaLocal: {49x75 cell}
                FormulaR1C1: {49x75 cell}
           FormulaR1C1Local: {49x75 cell}
                   HasArray: 0
                 HasFormula: 0
                     Height: 652.5000
                     Hidden: [1x228 char]
        HorizontalAlignment: 1
                IndentLevel: 0
                   Interior: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Interior]
                       Left: 0
             ListHeaderRows: 0
            LocationInTable: [1x237 char]
                     Locked: 1
                  MergeArea: 'Error: Object returned error code: 0x800A03EC'
                 MergeCells: 0
                       Name: 'Error: Object returned error code: 0x800A03EC'
                       Next: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
               NumberFormat: 'Standard'
          NumberFormatLocal: 'Standard'
                     Offset: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                Orientation: -4128
               OutlineLevel: [1x234 char]
                  PageBreak: [1x231 char]
                 PivotField: [1x232 char]
                  PivotItem: [1x231 char]
                 PivotTable: [1x232 char]
                 Precedents: [1x202 char]
            PrefixCharacter: ''
                   Previous: [1x230 char]
                 QueryTable: 'Error: Object returned error code: 0x800A03EC'
                     Resize: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                        Row: 1
                  RowHeight: NaN
                       Rows: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Range]
                 ShowDetail: [1x232 char]
                ShrinkToFit: 0
                  SoundNote: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.SoundNote]
                      Style: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Style]
                    Summary: [1x229 char]
                       Text: NaN
                        Top: 0
          UseStandardHeight: 1
           UseStandardWidth: 1
                 Validation: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Validation]
                      Value: {49x75 cell}
                     Value2: {49x75 cell}
          VerticalAlignment: -4107
                      Width: 4500
                  Worksheet: [1x1 Interface.Microsoft_Excel_11.0_Object_Library._Worksheet]
                   WrapText: 0
                    Comment: []
                   Phonetic: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Phonetic]
           FormatConditions: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.FormatConditions]
               ReadingOrder: -5002
                 Hyperlinks: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.Hyperlinks]
                  Phonetics: []
                         ID: 'Error: Object returned error code: 0x800A03EC'
                  PivotCell: 'Error: Object returned error code: 0x800A03EC'
                     Errors: 'Error: Object returned error code: 0x800A03EC'
                  SmartTags: [1x1 Interface.Microsoft_Excel_11.0_Object_Library.SmartTags]
                  AllowEdit: 1
                 ListObject: []
                      XPath: [1x579 char]
    Et DataRange ????
    Moi j'y vais à tattons là dessus

  6. #6
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 317
    Par défaut
    Après un petit test rapide, le code suivant devrait fonctionner :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    str=DataRange.Address
    [minCol,minLigne,maxCol,maxLigne]=strread(str(2:end),'%s%d:%s%d','delimiter','$')
    A tester

  7. #7
    Membre expérimenté Avatar de LordPeterPan2
    Inscrit en
    Février 2007
    Messages
    247
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 247
    Par défaut
    thanks folks

    J'essaierai quand on me demandera une amélioration

Discussions similaires

  1. Réponses: 4
    Dernier message: 24/05/2011, 14h38
  2. Recherche d'une cellule dans une feuille Excel
    Par vuong1 dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 23/03/2007, 07h51
  3. Problème de lecture des cellules dans une feuille Excel
    Par wangjun dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 08/10/2006, 09h35
  4. Couleur d'une cellule d'une feuille Excel
    Par FredericB dans le forum C++Builder
    Réponses: 3
    Dernier message: 13/09/2006, 22h09
  5. [VB6] Protection de cellules d'une feuille Excel
    Par Carole_Canada dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 15/02/2006, 19h08

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