Henry Olive 5 Posted November 13 Good Day I'm trying to Import Datas from Excel into a table When i scan the excel sheet i need to know in which column i am var Sheet, Book : Variant; begin Book:= ExcelApp.WorkBooks.Open(OD1.FileName); Sheet := Book.Worksheets[1]; for Col:= Low to High do begin if Sheet.Cell.Column = 2 then // (i need to get column number here), ERROR Method Cell not supported doThis; end; end; Share this post Link to post
DelphiUdIT 176 Posted November 13 I remeber somethings about decades ago ... may be the property is Sheet.Cells[x, y] or Sheets.Cells[x].Column ? For your facility, if you import the Excel typelib, you will able to see all properties of all "components" in the "Excel..._tlb.pas" created. These should be near the same as you use with OleObj. Share this post Link to post
Die Holländer 45 Posted November 13 Start making your own Excel object for your projects.. For example: constructor TExportExcel.Create; begin oXL := CreateOleObject('Excel.Application'); xlsClosed:=False; oXL.Visible := False; // Get a new workbook oWB := oXL.Workbooks.Add; oSheet := oWB.ActiveSheet; end; procedure TExportExcel.CloseExcel; begin oWB.Close; oXl.Quit; xlsClosed:=True; end; procedure TExportExcel.Open(aFileName: String); begin oXL.WorkBooks.Open(aFileName); oSheet := oXL.Workbooks[ExtractFileName(aFileName)].WorkSheets[1]; end; function TExportExcel.ColToText(aCol: integer): string; var d,m:integer; begin result:=''; if aCol<=0 then exit; aCol:=aCol-1; d:=aCol div 26; m:=aCol mod 26; result:=Char(ord('A')+m); if d>0 then begin result:=Char(ord('A')+d-1)+result; end; end; function TExportExcel.GetCell(aRow, aCol: integer): OLEVariant; begin result:=oSheet.Cells[aRow,aCol] end; procedure TExportExcel.SetCellBold(aRow, aCol: integer; const Value: OLEVariant); var oRng:OLEVariant; begin oSheet.Cells[aRow,aCol]:=Value; oRng:=oSheet.Range[CellToRange(aRow,aCol)]; oRng.Font.Bold:=True; end; procedure TExportExcel.SetCellValue(aRow, aCol: integer; const Value: OLEVariant); Begin oSheet.Cells[aRow,aCol].value := Value; End; Share this post Link to post
Henry Olive 5 Posted November 13 Thank you so much DelphiUdit, DieHollander Share this post Link to post