Working With Excel Sheets

By: Selva Balaji

Abstract: Using the Ole Automation Concept we can insert a picture, hyperlink and such a lot of things.

The Main Unit Has To Use the Office 97. Declare the Following in the Private Sections XLApp : Variant; The Main Unit Implementation Has to use ComObj,XLConst,Excel8TLB; If Office is available then the corresponding files like excel8tlb,office97 will be available. ComObj and XLConst are available in the delphisrc directory The Start the following coding in the button click event XLApp := CreateOleObject('Excel.Application'); XLApp.WorkBooks.Open('C:SELVA.xls'); XLApp.Visible := False; XLApp.DisplayAlerts:=False; //This code will add the bitmap file to the excel sheet XLApp.WorkBooks[1].WorkSheets[1].Shapes.AddPicture(FileName:='C:logo.bmp',LinkToFile:=False,SaveWithDocument:=True,Left:=10,Top:=10,Width:=400,Height:=300); //The Following code will add a hyperlink for the emails XLApp.WorkBooks[1].worksheets[1].cells[1,2].Formula := '=HYPERLINK("mailto:[email protected]","[email protected]")'; //This line will add a hyperlink to the website XLApp.WorkBooks[1].Worksheets[1].Hyperlinks.add(XLApp.WorkBooks[1].Worksheets[1].cells[1,4],''); //This will add a border around the cells XLApp.WorkBooks[1].WorkSheets[1].Range['A1:E5'].BorderAround (xlContinuous,xlThin,xlColorIndexAutomatic); //This will set the bmp as a background to the excel sheet XLApp.WorkBooks[1].WorkSheets[1].SetBackGroundPicture('c:logo.bmp'); //This will add a shape-rectangle to the excel sheet XLApp.WorkBooks[1].WorkSheets[1].Shapes.AddShape(msoShapeRectangle,144,144,72,72).Name:= 'Red Square'; XLApp.WorkBooks[1].WorkSheets[1].Shapes.AddShape(msoShapeRectangle,144,144,72,72).Line.DashStyle := msoLineDashDot; //You can define the column width using the following code XLApp.WorkBooks[1].WorkSheets[1].Columns.Columns[1].Columnwidth :=15; //Display the Operating system ShowMessage(XLApp.OperatingSystem); //You can save the file as different name XLApp.Workbooks[1].SaveAs('c:Selva1.xls',XLApp.Workbooks[1].fileformat); //This will save the current application XLApp.Save; //Quit the application XLApp.Quit; B. Selva Balaji. India

Server Response from: ETNASC03