|
Registriert seit: 26. Nov 2008 26 Beiträge |
#1
Hallo,
Durch googlen habe ich einen Code in einer französischen Webseite gefunden, wie man Excel durch Delphi steuern kann. Das Problem liegt daran, dass der Code fehlerhaft ist. Ich habe einige Fehler korrigiert, und die anderen wusste ich nicht wie ich die korrigiere Deswegen konnte ich leider das Programm nicht Kompilieren, könntet mir bitte helfen den Code zu korrigieren?? Die Fehler sind: [Error] Unit1.pas(78) : Undeclared identifier: 'Range' [Warning] Unit1.pas(451): Symbol 'Series' is specific to a platform [Warning] Unit1.pas(452): Symbol 'SeriesCollection' is specific to a platform [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas' Range ist schon definiert, aber der Kompilier erkennt das nicht. Übrigens ich benutze Delphi 7. Und der Code ist :
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComObj, OleServer, Db, DBTables, Grids, DBGrids, Excel2000, Variants; type TForm1 = class(TForm) Button1: TButton; ExcelApplication1: TExcelApplication; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Button8: TButton; Button9: TButton; Button10: TButton; Button11: TButton; Button12: TButton; Button13: TButton; Button14: TButton; Button15: TButton; Button16: TButton; Button17: TButton; Button18: TButton; Button19: TButton; Button20: TButton; Button21: TButton; Button22: TButton; Table1: TTable; Table1NAME: TStringField; Table1SIZE: TSmallintField; Table1WEIGHT: TSmallintField; Table1AREA: TStringField; DataSource1: TDataSource; DBGrid1: TDBGrid; Button23: TButton; Button24: TButton; Button25: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Button10Click(Sender: TObject); procedure Button11Click(Sender: TObject); procedure Button13Click(Sender: TObject); procedure Button14Click(Sender: TObject); procedure Button15Click(Sender: TObject); procedure Button16Click(Sender: TObject); procedure Button17Click(Sender: TObject); procedure Button18Click(Sender: TObject); procedure Button19Click(Sender: TObject); procedure Button20Click(Sender: TObject); procedure Button21Click(Sender: TObject); procedure Button22Click(Sender: TObject); procedure Button23Click(Sender: TObject); procedure Button24Click(Sender: TObject); procedure Button25Click(Sender: TObject); private { Déclarations privées } public { Déclarations publiques } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); begin ExcelApplication1.Connect; showmessage('Excel en Mémoire'); ExcelApplication1.Visible[1]:=true ; showmessage('Excel Visible'); ExcelApplication1.Workbooks.Add(emptyparam,1 ); showmessage('Classeur X Ajouté'); end; procedure TForm1.Button2Click(Sender: TObject); begin ExcelApplication1.Calculation[0]:=xlCalculationAutomatic; end; procedure TForm1.Button3Click(Sender: TObject); var AppExist :Boolean; Visible: OleVariant; FileName: OleVariant; ExcelApplication:Variant; Begin AppExist:=True; Try ExcelApplication:=GetActiveOleObject('Excel.Application'); // Ou Outlook.Application except on EOleSysError do AppExist:=False; end; if AppExist then begin ShowMessage('Excel est en cours d''exécution.'); Visible:=True; FileName:='Test1.Doc'; ExcelApplication.worksheets.Add(EmptyParam,EmptyParam,EmptyParam,Visible); end else ShowMessage('Excel n''est pas en cours d''exécution.'); end; procedure TForm1.Button4Click(Sender: TObject); var fichierXLS:OleVariant; MonClasseur : _workbook; begin // E:\Borland\NK_Test\Excel Work NK\Tuto.xls' fichierXLS :=extractfilepath(paramstr(0))+'Tuto.xls'; MonClasseur:=ExcelApplication1.Workbooks.Open(fichierXLS,False,False, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,0); ExcelApplication1.Visible[0]:=true; end; procedure TForm1.Button5Click(Sender: TObject); Var Resultat:OleVariant; begin Resultat := ExcelApplication1.GetOpenFilename; If Resultat='False' Then ShowMessage('Annulé !') Else ShowMessage(Resultat); end; procedure TForm1.Button6Click(Sender: TObject); Var Resultat:OleVariant; begin Resultat:=ExcelApplication1.InputBox('entrez une valeur','SAISIE','coucou',10,10); If Resultat='False' Then ShowMessage('Annulé !') Else ShowMessage(Resultat); end; procedure TForm1.Button7Click(Sender: TObject); begin if ExcelApplication1.CommandBars[1].Controls['Outils'].get_Enabled() then begin showmessage('Activé je vais le Désactivé...') ; ExcelApplication1.CommandBars[1].Controls['Outils'].Set_Enabled(false) end else begin showmessage('Désactivé je vais l''activé...');// 'Outils' Insertion ExcelApplication1.CommandBars[1].Controls['Outils'].Set_Enabled(true) end; end; procedure TForm1.Button8Click(Sender: TObject); var i:Smallint; begin if ExcelApplication1.CommandBars[1].Controls[2].get_Enabled() then for i := 2 to ExcelApplication1.CommandBars[1].Controls.Count do ExcelApplication1.CommandBars[1].Controls[i].Set_Enabled(false) else for i := 2 to ExcelApplication1.CommandBars[1].Controls.Count do ExcelApplication1.CommandBars[1].Controls[i].Set_Enabled(true) end; procedure TForm1.Button9Click(Sender: TObject); Var Resultat:OleVariant; begin Resultat:=ExcelApplication1.WorksheetFunction.Average(10,20,30,40,50,60, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam); ShowMessage(Resultat); end; procedure TForm1.Button10Click(Sender: TObject); begin if ExcelApplication1.DisplayAlerts[0]=False then ExcelApplication1.DisplayAlerts[0] :=true else ExcelApplication1.DisplayAlerts[0] :=False end; procedure TForm1.Button11Click(Sender: TObject); var MonClasseur : _workbook; begin //MonClasseur:=ExcelApplication1.Workbooks.Add(xlWBATWorksheet,0); ExcelApplication1.SheetsInNewWorkbook[0]:=5; MonClasseur:=ExcelApplication1.Workbooks.Add(EmptyParam,0); ExcelApplication1.Visible[0]:=true; end; procedure TForm1.Button13Click(Sender: TObject); var MonClasseur : _workbook; begin //Si un classeur est déjà ouvert dans Excel, il est possible d'en récupérer l'interface par If ExcelApplication1.Workbooks.Count>=1 Then MonClasseur:=ExcelApplication1.Workbooks[1]; end; procedure TForm1.Button14Click(Sender: TObject); var MonClasseur : _workbook; begin //Il est possible aussi de sélectionner le classeur par son nom ( sans l'extension ). MonClasseur:=ExcelApplication1.Workbooks['Tuto']; end; procedure TForm1.Button15Click(Sender: TObject); var MonClasseur : _workbook; begin If ExcelApplication1.Workbooks.Count>=1 Then MonClasseur:=ExcelApplication1.Workbooks[1]; MonClasseur.Close(False, emptyparam,emptyparam,0); ExcelApplication1.Free end; procedure TForm1.Button16Click(Sender: TObject); var MonClasseur : _workbook; begin //xlWBATChart : Feuille graphique If ExcelApplication1.Workbooks.Count>=1 Then //xlWBATExcel4MacroSheet : Feuille macro Excel 4 MonClasseur:=ExcelApplication1.Workbooks[1]; //xlWBATWorksheet : Feuille normale // Monclasseur.Sheets.Add(EmptyParam,EmptyParam,1,xlWBATWorksheet,0); Monclasseur.Sheets.Add(EmptyParam,monclasseur.Sheets[monclasseur.Sheets.count] ,1,xlWBATExcel4MacroSheet,0); end; procedure TForm1.Button17Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; begin If ExcelApplication1.Workbooks.Count>=1 Then //xlWBATExcel4MacroSheet : Feuille macro Excel 4 MonClasseur:=ExcelApplication1.Workbooks[1]; // Pour dupliquer la page sélectionnée sur plusieurs feuilles : MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; MonClasseur.Worksheets.FillAcrossSheets(MaFeuille.UsedRange[0],xlFillWithAll,0); end; procedure TForm1.Button18Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; begin If ExcelApplication1.Workbooks.Count>=1 Then //xlWBATExcel4MacroSheet : Feuille macro Excel 4 MonClasseur:=ExcelApplication1.Workbooks[1]; MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; MaFeuille.Copy(EmptyParam,Monclasseur.Sheets[Monclasseur.Sheets.Count],0); end; procedure TForm1.Button19Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; begin If ExcelApplication1.Workbooks.Count>=1 Then //xlWBATExcel4MacroSheet : Feuille macro Excel 4 MonClasseur:=ExcelApplication1.Workbooks[1]; MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; mafeuille.Shapes.AddOLEObject('Forms.CommandButton.1', Emptyparam,Emptyparam,Emptyparam,Emptyparam,Emptyparam,Emptyparam, 141, 28.5, 153, 27.75); end; procedure TForm1.Button20Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; begin If ExcelApplication1.Workbooks.Count>=1 Then //xlWBATExcel4MacroSheet : Feuille macro Excel 4 MonClasseur:=ExcelApplication1.Workbooks[1]; MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; ShowMessage(MaFeuille.Cells.Item[2,1].Value ); MaFeuille.Cells.Item[2,1].value:=12; end; procedure TForm1.Button21Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; rMaPlage : Range; begin If ExcelApplication1.Workbooks.Count>=1 Then //xlWBATExcel4MacroSheet : Feuille macro Excel 4 MonClasseur:=ExcelApplication1.Workbooks[1]; MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; rMaPlage:=MaFeuille.UsedRange[0]; //Attention : la plage définie par UsedRange est remise à jour par Excel //après des insertions ou suppression lors du prochain appel de UsedRange. //Par exemple l'adresse montrée ici n'est pas correcte : MaFeuille.Range['A2','A4'].EntireRow.Delete(xlUp); showMessage(vartostr(MaFeuille.Cells.SpecialCells(XlCellTypeLastCell,EmptyParam) .Address[True,True,xlA1,False,False])); //Il faut faire dans ce cas : //MaFeuille.Range['A2','A4'].EntireRow.Delete(xlUp); showMessage(vartostr(MaFeuille.UsedRange[0].SpecialCells(XlCellTypeLastCell,EmptyParam) .Address[True,True,xlA1,False,False])); //Pour récupérer la plage de cellules adjacentes sur la gauche à partir de A1 : rMaPlage:=MaFeuille.Range['A1',Mafeuille.Range['A1',EmptyParam].End_[xlToRight]]; //Pour récupérer la plage de cellules adjacentes vers le bas à partir de A1 : rMaPlage:=MaFeuille.Range['A1',Mafeuille.Range['A1',EmptyParam].End_[xlDown]]; //Pour récupérer une rMaPlage:=MaFeuille.Range['A1',EmptyParam].EntireRow; //Pour récupérer une colonne : rMaPlage:=MaFeuille.Range['A1',EmptyParam].EntireColumn; //Pour modifier la taille de la plage : rMaPlage:=MaFeuille.Range['A1',EmptyParam].Resize[4,5]; end; procedure TForm1.Button22Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; MonGraph: _Chart; ovFeuille: OLEvariant; colo,Rowo:Integer; begin //MonClasseur:=ExcelApplication1.Workbooks.Add(xlWBATWorksheet,0); ExcelApplication1.SheetsInNewWorkbook[0]:=1; MonClasseur:=ExcelApplication1.Workbooks.Add(EmptyParam,0); MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; //------------------------------------------ MaFeuille.Cells.Item[2,1].value:=12; Table1.first; for Colo:=0 to table1.FieldCount-1 do MaFeuille.Cells.Item[5,2+colo].value:=Table1.Fields[colo].FieldName; for rowo:= 1 to table1.RecordCount do begin MaFeuille.Cells.Item[5+rowo,5].value:= Table1AREA.Value ; MaFeuille.Cells.Item[5+rowo,4].value:= Table1SIZE.Value ; MaFeuille.Cells.Item[5+rowo,3].value:= Table1WEIGHT.Value ; MaFeuille.Cells.Item[5+rowo,2].value:= Table1NAME.Value ; table1.next end; //------------------------------------------ ExcelApplication1.Visible[0]:=true; ovFeuille:=MaFeuille; ovFeuille.Range['B5','B12'].Sort(MaFeuille.Range['B1','B1'], xlAscending, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, xlGuess, 1, False, xlTopToBottom, EmptyParam); (*Excel97 xlGuess, 1, False, xlTopToBottom, EmptyParam, EmptyParam, EmptyParam, EmptyParam); *) //-------------------------- Graph MaFeuille.Range['B5','C12'].Select; MonGraph:=MonClasseur.Sheets.Add(emptyparam,emptyparam,1,xlChart,0) as _chart; MonGraph.ChartType:= xl3DPieExploded ; MonGraph.Location(xlLocationAsObject,MaFeuille.Name); // //*------------------------- MaFeuille.Range['C13','D13'].Formula:='=SUM($C6:$C12)' ; MaFeuille.Range['C14','C14'].FormulaArray:='=SOMME(L6C3:L12C3)'; end; procedure TForm1.Button23Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; begin ExcelApplication1.SheetsInNewWorkbook[0]:=1; MonClasseur:=ExcelApplication1.Workbooks.Add(EmptyParam,0); MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; MaFeuille.Range['B1','E3'].Value:='Hello World Cellule Ajuster par largeur ...etc' ; ExcelApplication1.Visible[0]:=true; with MaFeuille.Range['A1','E3'] do begin Interior.ColorIndex := 46 ; Font.ColorIndex := 6 ; Font.Bold := True ; // Borders[xlEdgeBottom] ; xlEdgeRight xlEdgeBottom,xlEdgeTop,xlEdgeLeft, Borders.LineStyle := xlContinuous ; Borders.Weight := xlThin ; Borders.ColorIndex := xlAutomatic; end; MaFeuille.Range['I3','I3'].Select; //MaFeuille.Cells.FormulaR1C1 := 'sdgfdsfg'; MaFeuille.Range['I4','I4'].Select ; //Cells.FormulaR1C1 := 'dfgd' ; MaFeuille.Range['D7','D8'].Select ; MaFeuille.Range['D8','D8'].Activate ; MaFeuille.Range['B1','D3'].Columns.Autofit; MaFeuille.Range['C1','E3'].rows.Autofit; MaFeuille.Range['B2','C5'].BorderAround(xlDouble,xlThin,5,EmptyParam); MaFeuille.Range['A1','C5'].Font.Name:='times new roman'; MaFeuille.Range['A1','C5'].Font.Size:=14; MaFeuille.Range['A1','C5'].Font.Bold:=True; end; procedure TForm1.Button24Click(Sender: TObject); var MonClasseur : _workbook; MaFeuille : _worksheet; Colo,rowo :integer; begin MonClasseur:=ExcelApplication1.Workbooks[1]; MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; Table1.first; for Colo:=0 to table1.FieldCount-1 do MaFeuille.Cells.Item[5,2+colo].value:=Table1.Fields[colo].FieldName; for rowo:= 1 to table1.RecordCount do begin MaFeuille.Cells.Item[5+rowo,5].value:= Table1AREA.Value ; MaFeuille.Cells.Item[5+rowo,4].value:= Table1SIZE.Value ; MaFeuille.Cells.Item[5+rowo,3].value:= Table1WEIGHT.Value ; MaFeuille.Cells.Item[5+rowo,2].value:= Table1NAME.Value ; table1.next end; With MaFeuille.Range['D1','D20'].FormatConditions do begin Add(xlExpression,EmptyParam,'=NB.SI(C4;LC)>1',EmptyParam); Item(Count).Interior.ColorIndex:=3; end; end; procedure TForm1.Button25Click(Sender: TObject); var fichierXLS:OleVariant; MonClasseur : _workbook; MaFeuille :_Worksheet; MonGraph : _Chart; rMaPlage :Range; MaSerie : Series; MaCollSerie : SeriesCollection; compteur:integer; begin // E:\Borland\NK_Test\Excel Work NK\Tuto.xls' fichierXLS :=extractfilepath(paramstr(0))+'Tuto.xls'; MonClasseur:=ExcelApplication1.Workbooks.Open(fichierXLS,False,False, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,0); ExcelApplication1.Visible[0]:=true; MaFeuille:=MonClasseur.Worksheets[1] as _worksheet; rMaPlage:=MaFeuille.Range['D11','E19']; MonGraph:=MonClasseur.Sheets.Add(emptyparam,emptyparam,1,xlChart,0) as _chart; MonGraph.ChartType:=xlXYScatterLines; //MaCollSerie:=MonGraph.SeriesCollection(EmptyParam,0) as SeriesCollection; //MaSerie:=MaCollSerie.NewSeries; //MaSerie.FormulaLocal:='=SERIE(;Feuil1!$A$2:$A$21;Feuil1!$B$2:$B$21;1)'; end; end. |
![]() |
Ansicht |
![]() |
![]() |
![]() |
ForumregelnEs ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.
BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus. Trackbacks are an
Pingbacks are an
Refbacks are aus
|
|
Nützliche Links |
Heutige Beiträge |
Sitemap |
Suchen |
Code-Library |
Wer ist online |
Alle Foren als gelesen markieren |
Gehe zu... |
LinkBack |
![]() |
![]() |