Sunday, June 15, 2008

Reading Excel Spreadsheets from Delphi

The basic code looks like:

var
XlsObj : OleVariant;
BookObj : OleVariant;
SheetObj : OleVariant;

begin
XlsObj := CreateOleObject('Excel.Application');
XlsObj.DisplayAlerts := false; // prevent warnings from popping up
BookObj := XlsObj.Workbooks.Open(XlsFileName,,true); // readonly
SheetObj := BookObj.Sheets[SheetName];
do_some_work;
BookObj.Close(false);
end;

1 comment:

  1. Thanks buddy!!
    It helped me, else I was getting exception like excel automation. Can you just elaborate that what does false mean in close function?

    ReplyDelete