Salut,
D'après ce lien :
http://www.experts-exchange.com/Programming/Languages/P...
Ce code devrait te permettre d'importer des données Excel dans un String Grid :
procedure TfrmBeheerZendNota.sbtnImportFromExcelClick(Sender: TObject);
var
strWBName : String;
strWsName : String;
WorkBk : _WorkBook;
WorkSheet : _WorkSheet;
K, R, X, Y : Integer;
intX : Integer;
RangeMatrix : Variant;
blnSheetExist : Boolean;
begin
{ Initialise some variables. }
strWBName := 'MyWorkBook';
strWsName := 'Test';
{ Start Excel-Connection }
XLApp.Connect;
// Open the Excel File
XLApp.WorkBooks.Open(strWBName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,0);
WorkBk := XLApp.WorkBooks.Item[1];
blnSheetExist := False;
intX:=1;
While intX <= XLApp.Worksheets.Count do
begin
WorkSheet := WorkBk.Worksheets.Get_Item(intX) as _WorkSheet;
if WorkSheet.Name <> strWsName then
Inc(IntX)
else
begin
blnSheetExist := True;
Break;
end;
end;
if not blnSheetExist then
begin
MessageDlg('No Sheet exist with name : ' + strWsName, mtError, [mbOK], 0);
end
else
begin
WorkSheet := WorkBk.Worksheets.Get_Item(intX) as _WorkSheet;
// In order to know the dimension of the WorkSheet, i.e the number of rows and the
// number of columns, we activate the last non-empty cell of it
WorkSheet.Activate(intX);
WorkSheet.Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
// Get the value of the last row + column
X := XLApp.ActiveCell.Row;
Y := XLApp.ActiveCell.Column;
// Define the number of the columns in the TStringGrid
StringGrid1.ColCount := Y;
// Assign the Variant associated with the WorkSheet to the Delphi Variant Matrix
RangeMatrix := XLApp.Range['A1',XLApp.Cells.Item[X,Y]].Value;
// Quit Excel and Disconnect the Server
XLApp.Workbooks.Close(1);
XLApp.Quit;
XLApp.Disconnect;
// Define the loop for filling in the TStringGrid
K := 1;
repeat
for R := 1 to Y do
StringGrid1.Cells[(R - 1),(K - 1)] := RangeMatrix[K,R];
Inc(K,1);
StringGrid1.RowCount := K + 1;
until K > X;
// Unassign the Delphi Variant Matrix
RangeMatrix := Unassigned;
end;
end;