Delphi Control Excel (1) Methods using dynamic creation
First create an Excel object, use Comobj: Var Excelapp: Variant; ExceLapp: = CreateoleObject ('Excel.Application');
1) Display the current window: Excelapp.visible: = true;
2) Change the Excel Title Bar: Excelapp.caption: = 'Application MICROSOFT EXCEL';
3) Add a new workbook: excelapp.workbooks.add;
4) Open the existing workbook: excelapp.workbooks.open ('c: /excel/demo.xls');
5) Set the second worksheet as an active worksheet: eXcelapp.worksheets [2] .activate; or excelapp.workssheets ['sheet2'] .activate;
6) Give a unit value: Excelapp.cells [1,4] .value: = 'The first line of fourth column';
7) Set the width of the specified column (unit: characters), with the first list as an example: Excelapp.activesheet.columns [1] .Columnswidth: = 5;
8) Set the height of the specified line (1 pound = 0.035 cm), with the second behavior: Excelapp.activeesheet.Rows [2]. RowHeight: = 1 / 0.035; // 1 cm
9) Insert the pagan before 8 line: Excelapp.Worksheets [1] .Rows.pagebreak: = 1;
10) Delete Paging Password before column 8: Excelapp.activeesheet.columns [4] .pagebreak: = 0;
11) Specify the boundary width: Excelapp.activeesheet.Range ['b3: d4'] .borders [2] .weight: = 3; 1- Left 2- Right 3 - Top 4- 5- Occal (/) 6- Oblique (/)
12) Clear the first line of fourth column formula: Excelapp.activeesheet.cells [1,4] .clearContents;
13) Set the first line font attribute: Excelapp.activeesheet.Rows [1] .Font.Name: = '隶 书'; Excelapp.activeesheet.Rows [1] .font.color: = CLBLUE; Excelapp.activesheet.Rows [1 ] .Font.bold: = true; eXcelapp.activeesheet.rows [1] .font.underline: = true;
14) Make page settings:
a. Header: Excelapp.Activeesheet.pagesetup.centerheader: = 'Report Demo'; b. Footelapp.Activeesheet.pagesetup.centerfooter: = 'P.'; c. Header to Top Swardering 2CM: Excelapp .Activesheet.pagesetup.headermargin: = 2 / 0.035; d. Foot to the bottom margins 3cm: Excelapp.activesheet.pagesetup.headermargin: = 3 / 0.035; E. Top edge 2cm: Excelapp.activesheet.pagesetup.topMargin: = 2 / 0.035; f. Bottom margins 2cm: Excelapp.activeesheet.pagesetup.bottommargin: = 2 / 0.035; g. Left margins 2cm: Excelapp.activesheet.pagesetup.Leftmargin: = 2 / 0.035; h. Right margins 2cm: ExcelApp.ActiveSheet.PageSetup.RightMargin: = 2 / 0.035; i page centered horizontally:. ExcelApp.ActiveSheet.PageSetup.CenterHorizontally: = 2 / 0.035; j page vertically centered:. ExcelApp.ActiveSheet.PageSetup.CenterVertically: = 2 / 0.035 ; k. Print unit network cable: excelapp.activesheet.pagesetup.printgridlines: = true; 15) Copy operation:
a. Copy the entire worksheet: Excelapp.Activesheet.Used.range.copy; b. Copy Specify Area: Excelapp.Activeesheet.Range ['A1: E2'] .copy; c. Paste from the A1 position: Excelapp.activesheet. ['A1'] .pastespecial; d. Paste from the end of the file: Excelapp.activesheet.Range.Pastespecial;
16) Insert a row or a column: a. Excelapp.activesheet.Rows [2] .insert; b. Excelapp.activesheet.columns [1] .insert;
17) Delete a row or a column: a. Excelapp.activeesheet.Rows [2] .delete; b. Excelapp.activeesheet.columns [1] .delete;
18) Print preview worksheet: Excelapp.activesheet.printpreview;
19) Print Output Worksheet: Excelapp.Activesheet.Printout;
20) Worksheet Save: if NOTEXELAPPP.ActiveWorkbook.saved damp.activesheet.printpreview;
21) Worksheet is saved as: Excelapp.saveas ('C: /Excel/demo1.xls');
22) Abandon the deposit: eXcelapp.activeworkbook.saved: = true;
23) Close Workbook: ExceLapp.workbooks.close; 24) Exit Excel: Excelapp.quit;
(2) Use the Delphi control method to add Excelapplication, Excelworkbook, and Excelworksheet, respectively, in Form.
1) Open Excel Excelapplication1.Connect;
2) Display the current window: Excelapplication1.visible [0]: = true;
3) Change the Excel Title Bar: Excelapplication1.caption: = 'Application MICROFT Excel';
4) Add a new workbook: ExcelWorkbook1.ConnectTo (ExcelApplication1.Workbooks.Add (EmptyParam, 0)); 5) adding a new sheet: var Temp_Worksheet: _WorkSheet; beginTemp_Worksheet: = ExcelWorkbook1.WorkSheets.Add (EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0) as _WorkSheet; ExcelWorkSheet1.ConnectTo (Temp_WorkSheet); End; 6) to open an existing workbook: ExcelApplication1.Workbooks.Open (c: /a.xlsEmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EMPTYPARAM, 0)
7) Set the second worksheet as an active worksheet: Excelapplication1.Worksheets [2] .actiVate; or Excelapplication1.Workssheets ['Sheet2'] .actiVate;
8) Give a cell: Excelapplication1.cells [1,4] .value: = 'The fourth column of the first line;
9) Set the width of the specified column (unit: characters), with the first list as an example: excelapplication1.activeesheet.columns [1] .columnswidth: = 5;
10) Set the height of the specified line (1 pound = 0.035 cm), take the second behavior: excelapplication1.activesheet.rows [2]. RowHeight: = 1 / 0.035; // 1 cm
11) Insert the pagan before 8 line: Excelapplication1.Worksheets [1] .Rows.pagebreak: = 1;
12) Delete Page Nibes before column 8: Excelapplication1.Activeesheet.columns [4] .pagebreak: = 0;
13) Specify the boundary width: Excelapplication1.activesheet.Range ['B3: D4'] .borders [2] .weight: = 3; 1- Left 2- Right 3 - Top 4 - Bottom 5 - oblique (/) 6- Oblique (/)
14) Clear the first row of fourth column formula: excelapplication1.activeesheet.ceLls [1,4] .clearcontents; 15) Set the first line of font properties: Excelapplication1.Activeesheet.Rows [1] .font.name: = ' Lishu '; Excelapplication1.Activeesheet.Rows [1] .font.color: = CLBLUE; Excelapplication1.Activesheet.Rows [1] .font.bold: = true; Excelapplication1.Activeesheet.Rows [1] .font.underline: = true ;
16) Make page settings: a. Header: excelapplication1.activeesheet.pagesetup.centerheader: = 'report demonstration'; b. Footer: excelapplication1.activesheet.pagesetup.centerfooter: = 'P.'; c. Header to The top margins 2cm: Excelapplication1.activesheet.pagesetup.headermargin: = 2 / 0.035; d. Foot to the bottom margins 3cm: excelapplication1.activesheet.pagesetup.Headermargin: = 3 / 0.035; E. Top edge 2cm: Excelapplication1. ActiveSheet.PageSetup.TopMargin: = 2 / 0.035; f the bottom margin 2cm:. ExcelApplication1.ActiveSheet.PageSetup.BottomMargin: = 2 / 0.035; g 2cm from the left:. ExcelApplication1.ActiveSheet.PageSetup.LeftMargin: = 2 / 0.035; 2cm from the right side h: ExcelApplication1.ActiveSheet.PageSetup.RightMargin: = 2 / 0.035; i page centered horizontally:.. ExcelApplication1.ActiveSheet.PageSetup.CenterHorizontally:. = 2 / 0.035; j page vertically centered: ExcelApplication1.ActiveSheet.PageSetup. CenterVertically: = 2 / 0.035; k. Print Widgets: Excelapplication1.Activeesheet.pagesetup.printGridLines: = true;
17) Copy operation:
a. Copy the entire worksheet: Excelapplication1.Activeesheet.Used.range.copy;
b. Copy Specify Area: Excelapplication1.Activesheet.Range ['A1: E2'] .copy;
c. Paste from the position of A1: Excelapplication1.activesheet.Range. ['a1'] .pastespecial;
d. Paste from the end of the file: excelapplication1.activesheet.range.pastespecial;
18) Insert a row or a column: a. Excelapplication1.activesheet.Rows [2] .insert; b. EXcelapplication1.activeesheet.columns [1] .insert; 19) Delete a row or a column: a. Excelapplication1.activeesheet.rows [2] . Delapplication1.activesheet.columns [1] .delete;
20) Print preview worksheet: excelapplication1.activesheet.printpreview;
21) Print Output Worksheet: Excelapplication1.Activesheet.Printout;
22) Worksheet Save: if not excelapplication1.activeworkbook.saved dam s acElapplication1.activesheet.printpreview;
23) Worksheet is saved as: Excelapplication1.SAVEAS ('C: /Excel/demo1.xls');
24) Abandon the stock: Excelapplication1.activeWorkbook.saved: = true;
25) Close Workbook: Excelapplication1.Workbooks.close;
26) Exit Excel: Excelapplication1.quit; ExceLapplication1.disconnect;
(3) Use Delphi to control the excle 2D map in Form to add Excelapplication, Excelworkbook and Excelworksheetvar asheet1, Achart, Range: Variant;
1) Select when the first workmail first worksheet asheet1: = Excelapplication1.Workbooks [1] .Worksheets [1];
2) Add a two-dimensional map ACHART: = asheet1.ChartObjects.Add (100, 100, 200, 200);
3) Select the form of a two-dimensional map achart.Chart.ChartType: = 4;
4) Assigning the 2D map Series: = ACHART.CHART.SERIESCOLLECTION; RANGE: = Sheet1! R2C3: R3C9; Series.Add (Range, true); 5) Plus 2D graph Title Achart.Chart.hastitle: = True; achart.chart.charttitle.characters.text: = 'Excle two-dimensional map'
6) Change the title font size of the two-dimensional map. Achart.chart.charttitle.font.size: = 6;
7) Add a marking to the 2D map Description Achart.Chart.axes (xlcategory, xlprimary) .hartitle: = true; Achart.chart.axes (xlcategory, xlprimary) .axistitle.characters.text: = 'subscript description';
8) Add the ratio of the two-dimensional map. Abhart.Chart.axes (xlvalue, xlprimary) .hartitle: = true; achart.chart.axes (xlvalue, xlprimary) .axistle.characters.text: = 'left label description';
9) Plus the two-dimensional chart to the right mark. Achart.chart.axes (XlValue, XLsecondary) .hartitle: = true; Achart.chart.axes (xlvalue, xlsecondary) .axistitle.characters.text: = 'right label description'; 10) Change the size of the two-dimensional map of the display area achart.Chart.Plotarea.Eft: = 5; achart.Chart.Plotarea.width: = 223; Achart.Chart.Plotarea.Height: = 108;
11) Add the 2D map axis to describe ACHART.CHART.SERIESCOLLECTION [1] .Name: = 'coordinate axis description';
November 24, 2004 9:02
Copyright Notice: 9CBS is this BLOG managed service provider. If this paper involves copyright issues, 9CBS does not assume relevant responsibilities, please contact the copyright owner directly with the article Author.