Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > Lazarus, FreePascal, Kylix, etc.
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 09-01-2012
Avatar de jejo1984
jejo1984 jejo1984 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 39
Poder: 0
jejo1984 Va por buen camino
Abrir un archivo excel en un stringgrid con Lazarus IDE

Hola que tal amigos espero que me puedan ayudar con lo siguiente:
Bueno quiero abrir un archivo excel en un stringgrid con Lazarus IDE encontre algo similar en este foro pero me marca un error les enseño el codigo:

Código Delphi [-]
unit cf_acceso;  
{$mode objfpc}{$H+}  
interface  
uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,   Buttons,comobj,variants;
........ 
procedure TForm1.BitBtn1Click(Sender: TObject); 
const   xlCellTypeLastCell = $0000000B; 
var  Excel, Sheet,Book: OLEVariant;
CantRow, CantCol, i, j : Integer;
RangoMatriz: Variant;  FileName:String;
begin
FileName:='C:\SISTEMAPLANILLAS\Libro2.xlsx';
try
Excel := CreateOleObject('Excel.Application');
Excel.Workbooks.Open(FileName);
ShowMessage(FileName);
Sheet := Excel.Workbooks[ExtractFileName(FileName)].WorkSheets[1];   Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
CantRow := Excel.ActiveCell.Row;
CantCol := Excel.ActiveCell.Column;
RangoMatriz := Excel.Range['A1',Excel.Cells.Item[CantRow,CantCol]].Value;
for i:=1 to CantRow do
begin
for j:=1 to CantCol do
begin
Showmessage(RangoMatriz[i,j]);//haces todo lo que necesites hacer
end;
end;//for
finally
Excel.Quit; //Aquí cerramos la hoja de Excel 
end;
end;

Bien es en estas líneas de codigo en las que me aparece el error:

Código Delphi [-]
Sheet := Excel.Workbooks[ExtractFileName(FileName)].WorkSheets[1];
Error: Incompatible types: got "AnsiString" expected "LongInt"
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
RangoMatriz := Excel.Range['A1',Excel.Cells.Item[CantRow,CantCol]].Value;
Error: Incompatible types: got "Constant String" expected "LongInt"




Bueno intente esto:

Código Delphi [-]
Sheet := Excel.Workbooks[StrToInt(ExtractFileName(FileName))].WorkSheets[1]; Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;  RangoMatriz:=Excel.Range[StrToInt('A1'),Excel.Cells.Item[CantRow,CantCol]].Value;

Ejecuta normal pero al dar click en el boton aparece el mensaje:
El proyecto a lanzado una excepcion 'EOLeExceptionEOLeException' con el mensaje:
no se encontro "??????x.xlsx" Comprube ortografia y verificar si la ubicación es correcta.

La ruta es totalmente correcta pero no se lo que pasa por favor si me pueden ayudar con esto.
Gracias
Responder Con Cita
  #2  
Antiguo 10-01-2012
Avatar de jejo1984
jejo1984 jejo1984 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 39
Poder: 0
jejo1984 Va por buen camino
Hola por favor ayuden
Responder Con Cita
  #3  
Antiguo 10-01-2012
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.039
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Te recuerdo nuestra guía de estilo, gracias.
Responder Con Cita
  #4  
Antiguo 10-01-2012
Avatar de jejo1984
jejo1984 jejo1984 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 39
Poder: 0
jejo1984 Va por buen camino
Ya bueno casimiro se que ayuden no se debe de utilizar
Bueno tienen idea en que parte estoy fallando.
Responder Con Cita
  #5  
Antiguo 10-01-2012
Avatar de mightydragonlor
[mightydragonlor] mightydragonlor is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Medellín-Colombia
Posts: 587
Poder: 18
mightydragonlor Va por buen camino
No uses eso, mejor usa esto http://wiki.lazarus.freepascal.org/FPSpreadsheet, un muy buen control para hojas de calculo de excel.
__________________
mas confundido que Garavito el día del Niño.
Responder Con Cita
  #6  
Antiguo 11-01-2012
Avatar de jejo1984
jejo1984 jejo1984 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 39
Poder: 0
jejo1984 Va por buen camino
Claro pero yo quiero cargar el archivo en un TstringGrid......
Responder Con Cita
  #7  
Antiguo 11-01-2012
Avatar de mightydragonlor
[mightydragonlor] mightydragonlor is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Medellín-Colombia
Posts: 587
Poder: 18
mightydragonlor Va por buen camino
Lo cargas al FPSpreadsheet y lo lees para ingresar cada registro al string grid, si no estoy mal e, paquete de este control trae un ejemplo de esto.
__________________
mas confundido que Garavito el día del Niño.
Responder Con Cita
  #8  
Antiguo 11-01-2012
Avatar de jejo1984
jejo1984 jejo1984 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 39
Poder: 0
jejo1984 Va por buen camino
Instale el paquete que me indicas y sale este error:
Código Delphi [-]
Fatal: Can't find unit fpspreadsheetchart used by mainform
Responder Con Cita
  #9  
Antiguo 11-01-2012
Avatar de mightydragonlor
[mightydragonlor] mightydragonlor is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Medellín-Colombia
Posts: 587
Poder: 18
mightydragonlor Va por buen camino
Acá tratan este tema, espero te sirva de ayuda.
__________________
mas confundido que Garavito el día del Niño.
Responder Con Cita
  #10  
Antiguo 16-01-2012
Avatar de jejo1984
jejo1984 jejo1984 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 39
Poder: 0
jejo1984 Va por buen camino
No se puede hacer sin ese control!!!!
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Abrir un archivo txt en un StringGrid blackpic Varios 12 25-07-2013 19:44:22
Abrir un archivo de texto con excel Pitilingorri Varios 4 27-09-2011 12:24:04
Abrir archivo excel desde ruta Jeko Varios 4 28-03-2011 10:50:20
StringGrid con columnas igual al de un archivo Excel J@ckie Conexión con bases de datos 3 01-03-2011 15:07:20


La franja horaria es GMT +2. Ahora son las 04:07:47.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi