Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.10.10;
Скачать: CL | DM;

Вниз

импорт данных из excel   Найти похожие ветки 

 
stainer   (2004-09-11 16:56) [0]

Привет!
Как мне импортировать из excel данные в мою таблицу (ms access)

thanks!!!


 
GanibalLector ©   (2004-09-11 17:45) [1]

Например так :

function Xls_To_StringGrid(AGrid: TbsskinStringGrid; AXLSFile: string): Boolean;  
const  
xlCellTypeLastCell = $0000000B;  
var  
XLApp, Sheet: OLEVariant;
RangeMatrix: Variant;  
x, y, k, r: Integer;  
begin  
Result := False;  
// Create Excel-OLE Object
XLApp := CreateOleObject("Excel.Application");  
try  
  // Hide Excel  
  XLApp.Visible := False;  

  // Open the Workbook
  XLApp.Workbooks.Open(AXLSFile);

  // Sheet := XLApp.Workbooks[1].WorkSheets[1];  
  Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];  

  Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;  
  // Get the value of the last row  
  x := XLApp.ActiveCell.Row;

  // Get the value of the last column
  y := XLApp.ActiveCell.Column;
 
  // Set Stringgrid"s row &col dimensions.  

  AGrid.RowCount := x;
  AGrid.ColCount := y;

  // Assign the Variant associated with the WorkSheet to the Delphi Variant  

  RangeMatrix := XLApp.Range["A1", XLApp.Cells.Item[X, Y]].Value;
 { form1.memo1.lines.add(rangematrix); }
  //  Define the loop for filling in the TStringGrid  
  k := 1;  
  repeat  
    for r := 1 to y do  
      AGrid.Cells[(r - 1), (k - 1)] := RangeMatrix[K, R];  
    Inc(k, 1);
    AGrid.RowCount :=k+1;           {k+1}
  until k > x;          {>}
  // Unassign the Delphi Variant Matrix  
  RangeMatrix := Unassigned;

  Agrid.rowcount:=Agrid.rowcount-2;

finally  
  // Quit Excel  
  if not VarIsEmpty(XLApp) then  
  begin  
    // XLApp.DisplayAlerts := False;  
    XLApp.Quit;  
    XLAPP := Unassigned;  
    Sheet := Unassigned;  
    Result := True;  
  end;  
end;  
end;  


 
sniknik ©   (2004-09-11 18:21) [2]

а можно так (ADO - Jet - в подключении к базе access)
SELECT * INTO моятаблица FROM [Лист1$] IN "D:\файлехель.XLS" "Excel 8.0;"



Страницы: 1 вся ветка

Текущий архив: 2004.10.10;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.029 c
4-1094214152
Falcon
2004-09-03 16:22
2004.10.10
Как узнать какое окно в системе в текущий момент имеет ввод?


10-1045125852
alexfed
2003-02-13 11:44
2004.10.10
provider not exported : midas + socket connection


4-1094461814
Паскаль
2004-09-06 13:10
2004.10.10
button1.enabled:=sendmessage(...,em_canudo,0,0) выдает ошибку!


1-1095695552
volser
2004-09-20 19:52
2004.10.10
Редактирование ресурсов exe


6-1091101829
Татьяна
2004-07-29 15:50
2004.10.10
Загрузка web-странички