Topic: Help in read Excel column name
Very good day,
I would appreciate if you would support me. I am trying to get excel to read a column with a specific name, only that I can't find the form, the variable "result_string" is the one that I need to read the column in excel named "Registro", I want to read this column by name, why He's never in the same position
Greetings
procedure Inicio_VALL_OnClick (Sender: TObject; var Cancel: boolean);
var
Excel : Variant ;
Sheet : Variant ;
rows, columns : Integer;
MaxRow : Integer;
MaxCol : Integer;
result_string : string;
sql_string : string ;
sql_string2: string ;
irows : integer ;
sDate : string = FormatDateTime('yyyy-mm-dd', Inicio.DateTimePicker4.DateTime);
Cant:string;
Recaudado:string;
Linea:string;
Bingo:string;
begin
Excel:=CreateOleObject('Excel.Application');
//Excel.Visible:= True;
Excel.Workbooks.Open(Inicio.Edit4.Text) ;
Sheet := Excel.WorkSheets[1] ;
MaxRow := Sheet.Usedrange.EntireRow.count ;
MaxCol := sheet.Usedrange.EntireColumn.count;
//special excel[row,column]
irows := 0 ;
For rows := 10 To MaxRow Do
//columnas a contar de bajada///
Begin
For columns := 1 To 1 Do
Begin
result_string := '"'+Excel.ActiveSheet.Cells[rows,2].Text+'"';
Cant:= '"'+Excel.ActiveSheet.Cells[rows,6].Text+'"';
Recaudado:= '"'+Excel.ActiveSheet.Cells[rows,17].Text+'"';
Linea:= '"'+Excel.ActiveSheet.Cells[rows,8].Text+'"';
Bingo:= '"'+Excel.ActiveSheet.Cells[rows,9].Text+'"';
End;
sql_string :=
'INSERT central_psa(Jugada,Cant,Recaudado,Sala,Linea,Bingo,Fecha_carga) values('
+result_string+','+Cant+','+Recaudado+',"Vallarta",'+Linea+','+Bingo+','''+sDate+''');';
SQLExecute('Delete from central_psa where Cant = 0') ;
Inicio.Memo4.Lines.Add(sql_string) ;
irows := irows +1 ;
result_string := '' ;
sql_string := '' ;
Inicio.Label12.Caption := IntToStr(irows);
////ultimo
End;
KillTask('EXCEL.EXE');
end;