It just so happens that I can assist
One of the applications I created at work can import data directly from Excel spreadsheets. It requires Excel to be installed on the machine, but uses late binding to get around potential version differences.
Code:
fExcelApp:=CreateOleObject('Excel.Application');
if (not varIsEmpty(fExcelApp)) then
begin
if (fConfiguration.workbookPassword<>'') then
begin
password:=fConfiguration.workbookPassword;
end
else
begin
password:='ThisIsAnEmptyPassword'; // emptyParam;
end;
try
fExcelApp.Workbooks.Open(sourceFilename,ReadOnly:=true,UpdateLinks:=false,Password:=password);
except
on e:exception do
begin
fExcelApp.Quit
exit;
end;
end;
try
fExcelWorkbook:=fExcelApp.ActiveWorkbook;
except
on e:Exception do
begin
fExcelWorkbook:=null;
fExcelApp.Quit;
exit;
end;
end;
if (fExcelWorkbook.Worksheets.Count>0) then
begin
sheetName:=fConfiguration.worksheetName;
try
fExcelWorksheet:=fExcelWorkbook.Worksheets.Item[sheetName];
except
on e:exception do
begin
fExcelWorksheet:=null;
fExcelWorkbook:=null;
fExcelApp.quit;
exit;
end;
end;
end;
// Access the cells in the open worksheet like this:- fExcelWorksheet.cells.item[1,column]
fExcelWorksheet:=null;
fExcelWorkbook:=null;
fExcelApp.quit;
end;
fExcelApp, fExcelWorkbook and fExcelWorksheet are all OleVariants. I can't post anymore than this snippet (which is lacking ALOT of error checking) as it's code from the product itself. For more information about the various methods etc. available to you, your best bet is the Microsoft Interop References (http://msdn.microsoft.com/en-us/libr...ice.15%29.aspx - For Excel). It can be a real pain in the proverbial backside but once you get used to using them and working in this way you can do an awful lot. The same app that imports from Excel also opens InfoPath forms, renders them to a PDF document and copies all the attachments out to self contained files for later processing... all done in a similar convoluted fashion.
If you have further questions, feel free to ask
Bookmarks