First create an Excel object, using ComObj: var ExcelApp: Variant; ExcelApp := CreateOleObject( 'Excel.application' ); Note that the variable ExcelApp:=unassigned at the end of the program is released; 1 Display the current window: ExcelApp.Visible := True; 2 Change Excel title bar: ExcelApp.Caption := 'Application calls Microsoft Excel'; 3 Add a new workbook: ExcelApp.WorkBooks.Add; 4 Open an existing workbook: ExcelApp.WorkBooks.Open( 'C:ExcelDemo.xls' ); 5 Set the second worksheet as the active worksheet: ExcelApp.WorkSheets[2].Activate; or ExcelApp.WorksSheets[ 'Sheet2' ].Activate; Add worksheet ExcelApp.WorkSheets.add; Rename the worksheet ExcelApp. WorkSheets[1].Name:='Worksheet1'; or ExcelApp.WorkSheets['Sheet1'].Name:='Worksheet1'; Number of worksheets ExcelApp.WorkSheets.Count 6 Assign value to cells: ExcelApp.Cells [1,4].Value := 'Fourth column in the first row'; 7 Set the width of the specified column (unit: number of characters), take the first column as an example: ExcelApp.ActiveSheet.Columns[1].ColumnsWidth: = 5; 8 Set the height of the specified row (unit: pound) (1 pound = 0.035 cm), taking the second behavior example: ExcelApp.ActiveSheet.Rows[2].RowHeight := 1/0.035; // 1 cm 9 in Insert page breaks before line 8: ExcelApp.WorkSheets[1].Rows.PageBreak := 1; 10 Delete page breaks before column 8: ExcelApp.ActiveSheet.Columns[4].PageBreak := 0; 11 Specify border line Width: ExcelApp.ActiveSheet.Range[ 'B3:D4' ].Borders[2].Weight := 3; 1-Left 2-Right 3-Top 4-Bottom 5-Slant ( ) 6-Slant ( / ) 12 Clear The cell formula of the first row and fourth column: ExcelApp.ActiveSheet.Cells[1,4].ClearContents; 13 Set the font properties of the first row: ExcelApp.ActiveSheet.Rows[1].Font.Name := 'Lishu'; ExcelApp .ActiveSheet.Rows[1].Font.Color := clBlue; ExcelApp.ActiveSheet.Rows[1].Font.Bold := True; ExcelApp.ActiveSheet.Rows[1].Font.UnderLine := True; 14 Proceed to the page Settings: a. Header: ExcelApp.ActiveSheet.PageSetup.CenterHeader := 'Report Demo'; b. Footer: ExcelApp.ActiveSheet.PageSetup.CenterFooter := 'Page&P'; c. Header to top margin 2cm : ExcelApp.ActiveSheet.PageSetup.HeaderMargin := 2/0.035; d. Footer to bottom margin 3cm: ExcelApp.ActiveSheet.PageSetup.HeaderMargin := 3/0.035; e. Top margin 2cm ExcelApp.ActiveSheet.PageSetup.TopMargin := 2/0.035; f. Bottom margin 2cm ExcelApp.ActiveSheet.PageSetup.BottomMargin := 2/0.035; g. Left margin 2cm: ExcelApp.ActiveSheet.PageSetup.LeftMargin := 2/0.035; h. Right margin 2cm: ExcelApp.ActiveSheet.PageSetup.RightMargin := 2/0.035; i. The page is centered horizontally: ExcelApp.ActiveSheet.PageSetup.CenterHorizontally:= 2/0.035; j. The page is centered vertically: ExcelApp.ActiveSheet.PageSetup.CenterVertically:= 2/0.035 ; k. Print cell network cable: ExcelApp.ActiveSheet.PageSetup.PRintGridLines := True; 15 Copy operation: a. Copy the entire worksheet: ExcelApp.ActiveSheet.Used.Range.Copy; b. Copy the specified area: ExcelApp.ActiveSheet. Range[ 'A1:E2' ].Copy; c. Start pasting from A1 position: ExcelApp.ActiveSheet.Range.[ 'A1' ].PasteSpecial; d. Start pasting from the end of the file: ExcelApp.ActiveSheet.Range.PasteSpecial; 16 Insert a row or column: a. ExcelApp.ActiveSheet.Rows[2].Insert; b. ExcelApp.ActiveSheet.Columns[1].Insert; 17 Delete a row or column: a. ExcelApp.ActiveSheet.Rows[2].Delete; b. ExcelApp.ActiveSheet.Columns[1].Delete; 18 Print preview worksheet: ExcelApp.ActiveSheet.PrintPreview; 19 Printout worksheet: ExcelApp.ActiveSheet.PrintOut; 20 Worksheet save: if not ExcelApp.ActiveWorkBook.Saved then ExcelApp.ActiveSheet.PrintPreview; 21 Save the worksheet as: ExcelApp.SaveAs( 'C:ExcelDemo1.xls' ); 22 Discard saving: ExcelApp.ActiveWorkBook.Saved := True; 23 Close the workbook: ExcelApp.WorkBooks.Close; 24 Exit Excel: ExcelApp.Quit;