Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Spreadsheet update
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00317983
Message ID:
00360977
Vues:
14
Don,

I experimented with your code with a spreadsheet of mine, and it appeared to run okay. However, I changed the way the Excel object is created. Your code is assigning an object reference to the property of a custom object. When I tested it, the Excel object was not being released when the application finished, leaving an instance of Excel in memory. ("RELEASE .r_oXlsSess" causes an error.) After several attempts at running the program, I was left with a number of Excel instances, and my system ended up with a GPF.

I changed the Excel object to a public variable called oExcel, and changed all occurrences of ".r_oXlsSess" to "oExcel", and it appeared work much better.

I suggest you ensure you are not creating multiple instances of Excel during your testing, and consider modifying how you are setting up the Excel connection.

Good luck!

Michael Reynolds


>First I launch excel and get the object reference . . .
WITH This
  * Test to see if an object already exists, If not - do it
  *
  lcSessType	= VARTYPE( .r_oXlsSess )
  IF lcSessType <> 'O'
    .r_oXlsSess = CREATEOBJECT( 'Excel.Application' )
  ENDIF
  * Open the file, then get a reference to the First Worksheet
  *
  .r_oXlsSess.WorkBooks.Open( lcFileName )
  .r_oXlsSheet= .r_oXlsSess.ActiveWorkBook.ActiveSheet

  * Go to the upper left corner, then the bottom of the first column
  * and get the last Cell (row/col) reference
  *
  .r_oXlsSess.Range("A1").Select
  .r_oXlsSess.Selection.End( -4121 ).Select
  .r_nRowTotl = .r_oXlsSess.Selection.Row

  * Go to the upper left corner,
  * Go to the right on this row till:
  * a) last cell with data or,
  * b) next cell with data
  * and get the last Cell (row/col) reference
  *
  .r_oXlsSess.Range("A1").Select
  .r_oXlsSess.Selection.End( 2 ).Select
  .r_nColTotl = .r_oXlsSess.Selection.Column

  IF VARTYPE( .r_aStruAray[ 1, 1 ] ) = 'C'
    .r_nColTotl	= ALEN( .r_aStruAray, 1 )
  ELSE
    l_Colhdg	= .m_GetSrcDta( 1 )
    IF VARTYPE( l_ColHdg ) = 'C'
      .r_lValidateColName = .F.
      .r_nStrtRow = 2
    ENDIF
  ENDIF
  .r_lHeadIngs= ( .r_nStrtRow = 2 )

ENDWITH
>Then, by iterating through the identified matrix limits ( .r_oXlsSess.RowTotl, .r_oXlsSess.ColTotl ), I capture the
>data in each cell to a memvar.
>
> l_RetVal = .r_oXlsSheet.Cells( .r_nRowId, .r_nColId ).Value
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform