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]);end;
end;finally
Excel.Quit; 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