Excel - error al importar

HMG en Español

Moderator: Rathinagiri

Mario Mansilla
Posts: 270
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina

Excel - error al importar

Post by Mario Mansilla »

Hola Amigos :
les adjunto un pequeño proyecto para que puedan ayudarme a encontrar el problema que causa que a veces al importar la planilla excel me da los mensajes de error que muestra el archivo errorlog .
La planilla excel esta en la carpeta importacion , hacen click en la lupa y buscan la planilla y luego aceptar .

Desde ya muchas gracias
Saludos
Mario Rafael Mansilla

Hi friends :
I am attaching a small project so that you can help me find the problem that sometimes when importing the excel spreadsheet it gives me the error messages that the errorlog file shows.
The excel spreadsheet is in the import folder, click on the magnifying glass and look for the spreadsheet and then accept.

From already thank you very much
Greetings
Mario Rafael Mansilla
Attachments
Excel.rar
(2.33 MiB) Downloaded 200 times
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Excel - error al importar

Post by SALINETAS24 »

Mario Mansilla wrote: Tue Dec 14, 2021 4:13 pm Hola Amigos :
les adjunto un pequeño proyecto para que puedan ayudarme a encontrar el problema que causa que a veces al importar la planilla excel me da los mensajes de error que muestra el archivo errorlog .
La planilla excel esta en la carpeta importacion , hacen click en la lupa y buscan la planilla y luego aceptar .

Desde ya muchas gracias
Saludos
Mario Rafael Mansilla

Hi friends :
I am attaching a small project so that you can help me find the problem that sometimes when importing the excel spreadsheet it gives me the error messages that the errorlog file shows.
The excel spreadsheet is in the import folder, click on the magnifying glass and look for the spreadsheet and then accept.

From already thank you very much
Greetings
Mario Rafael Mansilla
Hola Mario, lo puedes solucionar haciendo una copia de los datos a una nueva Hoja de Calculo, solo tienes que copiar los datos, sin cabecera ni ordenaciones. Por lo visto el problema viene dado por tener la hoja de calcula la cabecera fija.

Con esto ya lo tienes.., salud y una cervecita fresquita.
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Excel - error al importar

Post by serge_girard »

I think there is an error in the sheet. Try to save it as CSV and then edit in your program editor.
There's nothing you can do that can't be done...
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Excel - error al importar

Post by SALINETAS24 »

serge_girard wrote: Wed Dec 15, 2021 8:49 am I think there is an error in the sheet. Try to save it as CSV and then edit in your program editor.
Hola Serge, no creo que la hoja tenga errores, creo en mi humilde opinión que tiene por un lado algo de programación y tambien 3 páginas ocultas que tienen vinculación con la Excel principal..., :evil: todo unido al parecer dificulta la importación. Muestro la imagen.

Si por el contrario se copian los datos a una nueva hoja (cotar y pegar), el funcionamiento es correcto.

Igual alguien (y ahora que tenemos más datos), sabe como se prodria importar una hoja de estas caracteristicas sería estupendo.

Vamos con esa cervecita fresquita!!!
Attachments
excel1.JPG
excel1.JPG (9.84 KiB) Viewed 5396 times
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
AUGE_OHR
Posts: 2096
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Excel - error al importar

Post by AUGE_OHR »

hi,

this Code "crash" when want to "select" (in wrong Way)

Code: Select all

   oExcel:WorkBooks:Open( cArchivo )
   oExcel:Sheets(nHoja):Select() -> crash 
// "Error WINOLE/1009 No exported method SHEETS Parameter : [ 1] = N 1 (DOS Error -2147418111)
   oHoja := oExcel:ActiveSheet()
try it this Way

Code: Select all

   oBook  := oExcel:Workbooks:Open(cExcelFile)
   oSheet := oBook:ActiveSheet
   oRange := oSheet:usedRange
   nCol := oRange:Columns:Count() 
   nRow := oRange:Rows:Count()   
now i have to ask : do you want to get hole Sheet :?:

if yes
use nRow /nCol (convert to A-Z) to "select Range" and copy/paste it to Array with "same Size"

Code: Select all

   aExcel := ARRAY(nRow,nCol)
   cEnde := ZAHL2CHR(nCol)
   // now "fill" Array from Sheet Range
   aExcel := oSheet:range( "A1:"+cEnde+LTRIM( STR(nRow) ) ):value

---

you also can "fill" a Excel Sheet this Way

Code: Select all

   oSheet:range( "A1:"+cEnde+LTRIM( STR( nRow ) ) ) :value := aExcel
have fun
Jimmy
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Excel - error al importar

Post by edk »

@Serge, SALINETAS24, Jimmy
It's not exactly what you suggest.
it is just that the workbook has not yet been fully loaded into Excel and therefore does not yet have sheet objects.

See a simple test:

Code: Select all

...
nHoja := 1
oExcel:WorkBooks:Open( cArchivo )
Sleep ( 1000 )
oExcel:Sheets(nHoja):Select()
oHoja := oExcel:ActiveSheet()
...
@ Mario Mansilla
See this solution:

Code: Select all

...
nHoja := 1
oExcel:WorkBooks:Open( cArchivo )

// catch any errors
bErrBlck := ErrorBlock( { | oError | ExcelError( oError ) } )

lIsExcelFullyLoaded := .F.

DO WHILE .NOT. lIsExcelFullyLoaded
	BEGIN SEQUENCE
		nSheets := oExcel:Sheets:Count
		lIsExcelFullyLoaded := .T.
	RECOVER 
		lIsExcelFullyLoaded := .F.
	END
ENDDO

//Restore the previous ErrorBlock
ErrorBlock( bErrBlck )

oExcel:Sheets(nHoja):Select()
oHoja := oExcel:ActiveSheet()
...

...
**************************************************************
FUNCTION ExcelError( oError )
BREAK oError
RETURN Nil
User avatar
AUGE_OHR
Posts: 2096
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Excel - error al importar

Post by AUGE_OHR »

hi Edward,

you are right that is is a Problem of "timeing"
thats why i do use "single Step" to get oBook, oSheet and oRange to avoid "sleep"
have fun
Jimmy
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Excel - error al importar

Post by edk »

AUGE_OHR wrote: Wed Dec 15, 2021 9:55 pm hi Edward,

you are right that is is a Problem of "timeing"
thats why i do use "single Step" to get oBook, oSheet and oRange to avoid "sleep"
+1
I agree, in addition, such a code is more transparent.
User avatar
mol
Posts: 3805
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Excel - error al importar

Post by mol »

I'm using xlsxclass to read data from Excel in one of my application. It's fast and no Excel is needed
User avatar
Rathinagiri
Posts: 5481
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Excel - error al importar

Post by Rathinagiri »

Man! You are God sent!
edk wrote: Wed Dec 15, 2021 2:17 pm @Serge, SALINETAS24, Jimmy
It's not exactly what you suggest.
it is just that the workbook has not yet been fully loaded into Excel and therefore does not yet have sheet objects.

See a simple test:

Code: Select all

...
nHoja := 1
oExcel:WorkBooks:Open( cArchivo )
Sleep ( 1000 )
oExcel:Sheets(nHoja):Select()
oHoja := oExcel:ActiveSheet()
...
@ Mario Mansilla
See this solution:

Code: Select all

...
nHoja := 1
oExcel:WorkBooks:Open( cArchivo )

// catch any errors
bErrBlck := ErrorBlock( { | oError | ExcelError( oError ) } )

lIsExcelFullyLoaded := .F.

DO WHILE .NOT. lIsExcelFullyLoaded
	BEGIN SEQUENCE
		nSheets := oExcel:Sheets:Count
		lIsExcelFullyLoaded := .T.
	RECOVER 
		lIsExcelFullyLoaded := .F.
	END
ENDDO

//Restore the previous ErrorBlock
ErrorBlock( bErrBlck )

oExcel:Sheets(nHoja):Select()
oHoja := oExcel:ActiveSheet()
...

...
**************************************************************
FUNCTION ExcelError( oError )
BREAK oError
RETURN Nil
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply