Uses Comobj, Excel97, Excel2000;
// Write data from Excel to Access library prodeducE ExceltomDB (exlile: string;); variant; xipp, workbook: variant; irow, maxrow: integer; begin screen.cursor: = cr Hourglass ;? try // creation object xlapp: = createOleObject ( 'Excel.Application'); XLApp.displayAlerts: = false; XLApp.ScreenUpdating: = false; XLApp.WorkBooks.Add (EXLfile); workbook: = XLApp.workbooks [1]; sheet: = workbook.worksheets [1 ]; //Sheet:=Xlapp.workbooks[1].worksheets[1]; // Get the maximum number of rows? Maxrow Xlapp.Activecell.Specialcells (XLlastcell) .select; maxrow: = xlapp.activecell.row; // Max The number of lines maxcol: = xlapp.activecell.column; // maximum number
// Write data to Access library adotable1.open; for irow: = 2 to maxrow do if sheet.cells [iRow, 1] <> '' Then? // Keywords are not empty begin adotable1.append; adotable1.fieldbyname 'Id'). Asinteger: = start (Sheet.cells [iRow, 1]); adotable1.fieldbyname ('code'). Asstring: = sheet.cells [iRow, 2];? // encoded adotable1.fieldbyname (' Name '). asstring: = sheet.cells [iRow, 3];? // Name adotable1.post; end;
Finally if not varisempty (xlapp) THEN BEGIN® // Release Object xlapp.displayalerts: = false; xlapp.screenupdating: = true; xlapp.quit; end; screen.cursor: = crdefault; End; end;
/ / =================== Other attribute methods ================ //
Currow: = xlapp.activecell.row;? // Current Row XLAPP.DISPLAYALERTS: = false; ??? // Whether to display warning and message XLAPP.SCREENUPDADATION: = false ;? // screen update function, improve Speed; // After running, ScreenupDating set back to TRUE
XLapp.Run ('macroname', params ...) // run macro