Hola...
Tendo una duda estoy importando un archivo de excel a firebird pero cuando me quiero cambiar de hoja, me marca
error en el metodo Activate de la clase Range, el codigo q estoy usando es el siguiente:
Código Delphi
[-]
if EdtContacto.Text <> '' then
begin
if not FileExists(EdtContacto.Text) then
begin
Application.MessageBox(pchar(format('Error 001: No se encontró el archivo %s.'#13'Capture un archivo válido y vuelva a intentarlo.', [EdtContacto.Text])), pchar(self.Caption), MB_OK + MB_ICONERROR);
EdtContacto.SetFocus;
Exit;
end;
end;
memLog.Lines.Add('Inicio de lectura de archivo de Prensa...');
try
Excel := CreateOleObject('Excel.Application');
Excel.Workbooks.Open(EdtContacto.Text);
Sheet := Excel.Workbooks[ExtractFileName(EdtContacto.Text)].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;
CdsPrensa:=Tclientdataset.create(nil);
for i:=1 to CantRow do
begin
for j:=1 to CantCol do
begin
if i = 1 then
begin
campoLetras:=TStringField.Create(self);
with campoLetras do
begin
FieldName:=RangoMatriz[i,j];
DataSet:=CdsPrensa;
if j = CantCol then
begin
CdsPrensa.Close;
CdsPrensa.CreateDataSet;
end;
end;
end
else
begin
if i <> o then
CdsPrensa.Append;
CdsPrensa.Fields.Fields[j-1].AsString :=RangoMatriz[i,j];
end;
o:= i;
end;
end;
CdsPrensa.Post;
dtsPrensa.DataSet:=CdsPrensa;
aView.DataController.Filter.Clear;
aView.DataController.DataSource := dtsPrensa;
aview.BeginUpdate;
RemoveAllColumns(aView);
aView.DataController.CreateAllItems;
aView.EndUpdate;
memLog.Lines.Add('Termino la carga de Televisión...');
{$ENDREGION}
memLog.Lines.Add('Inicio de lectura de archivo de Televisión...');
try
Excel := CreateOleObject('Excel.Application');
Excel.Workbooks.Open(EdtContacto.Text);
Sheet := Excel.Workbooks[ExtractFileName(EdtContacto.Text)].WorkSheets[2];
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate; "Aqui me marca el error"
CantRow := Excel.ActiveCell.Row;
CantCol := Excel.ActiveCell.Column;
RangoMatriz := Excel.Range['A1', Excel.Cells.Item[CantRow,CantCol]].Value;
Cdstele:=Tclientdataset.create(nil);
for i:=1 to CantRow do
begin
for j:=1 to CantCol do
begin
if i = 1 then
begin
campoLetras:=TStringField.Create(self);
with campoLetras do
begin
FieldName:=RangoMatriz[i,j];
DataSet:=CdsTele;
if j = CantCol then
begin
cdsTele.Close;
cdsTele.CreateDataSet;
end;
end;
end
else
begin
if i <> o then
cdsTele.Append;
cdsTele.Fields.Fields[j-1].AsString :=RangoMatriz[i,j];
end;
o:= i;
end;
end;
cdsTele.Post;
dtsTelevision.DataSet:=cdsTele;
aViewTv.DataController.Filter.Clear;
aViewTv.DataController.DataSource := dtsTelevision;
aviewTv.BeginUpdate;
RemoveAllColumns(aViewTv);
aViewTv.DataController.CreateAllItems;
aViewTv.EndUpdate;
finally
memLog.Lines.Add('Termino la carga de Televisión...');
Excel.Quit;
end;
Les agradezco de antemano su ayuda... pasa la informacion de la primera hoja sin problema y al querer cargar la informacion de la segunda hoja me salta ese error...