Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Lazarus, FreePascal, Kylix, etc. (https://www.clubdelphi.com/foros/forumdisplay.php?f=14)
-   -   Abrir un archivo excel en un stringgrid con Lazarus IDE (https://www.clubdelphi.com/foros/showthread.php?t=77273)

jejo1984 09-01-2012 23:39:43

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

jejo1984 10-01-2012 13:13:42

Hola por favor ayuden

Casimiro Notevi 10-01-2012 13:37:09

Te recuerdo nuestra guía de estilo, gracias.

jejo1984 10-01-2012 13:42:48

Ya bueno casimiro se que ayuden no se debe de utilizar
Bueno tienen idea en que parte estoy fallando.

mightydragonlor 10-01-2012 22:25:11

No uses eso, mejor usa esto http://wiki.lazarus.freepascal.org/FPSpreadsheet, un muy buen control para hojas de calculo de excel.

jejo1984 11-01-2012 13:07:46

Claro pero yo quiero cargar el archivo en un TstringGrid......

mightydragonlor 11-01-2012 13:50:47

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.

jejo1984 11-01-2012 14:35:37

Instale el paquete que me indicas y sale este error:
Código Delphi [-]
Fatal: Can't find unit fpspreadsheetchart used by mainform

mightydragonlor 11-01-2012 15:22:48

Acá tratan este tema, espero te sirva de ayuda.

jejo1984 16-01-2012 14:46:49

No se puede hacer sin ese control!!!!


La franja horaria es GMT +2. Ahora son las 05:36:40.

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