Difference between revisions of "ExcelAutomation/de"
m (Fixed syntax highlighting) |
|||
(85 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ExcelAutomation}} | {{ExcelAutomation}} | ||
− | |||
− | |||
− | |||
− | |||
<br> | <br> | ||
− | =Speicherplatz reservieren= | + | Zurück zur [[Office Automation/de|Office Automation]].<br> |
− | <syntaxhighlight> | + | <br> |
+ | __TOC__ | ||
+ | <br> | ||
+ | =Excel= | ||
+ | Alle Möglichkeiten der Excelautomation aufzuzeigen ist nicht möglich ich hoffe aber für jeden Bedarf Anregungen gefunden zu haben.<br> | ||
+ | Excel ist zu dem die automatisierungsfreundlichste Software von Microsoft.<br> | ||
+ | Wenn Sie Umlaute usw. verwenden, dann sollten Sie wissen, dass Excel UTF16 codierte Strings verwendet.<br> | ||
+ | Für die Oleautomation muss die Unit '''ComObj''' eingebunden werden.<br> | ||
+ | Für die Verwendung von Umlauten usw. muss die Unit '''lclproc''' eingebunden werden.<br> | ||
+ | <br> | ||
+ | ==Speicherplatz reservieren== | ||
+ | <syntaxhighlight lang=pascal> | ||
var | var | ||
− | + | varXLApp: oleVariant; // wird für die Adressierung des Programms Excel verwedet | |
+ | varXLWb: oleVariant; // wird für die Adressierung des Exceldatei verwendet | ||
+ | wstrUebergabe: WideString; // Hilfsvariable (wird z. B. für Umlaute usw. benötigt) | ||
+ | wstrRange: WideString // Hilfsvariable für eine Range | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | =Excel OleObjekt erstellen= | + | |
− | <syntaxhighlight> | + | ==Excel OleObjekt erstellen== |
+ | <syntaxhighlight lang=pascal> | ||
+ | uses | ||
+ | comobj; | ||
+ | |||
begin | begin | ||
... | ... | ||
Line 24: | Line 38: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | =Excel | + | |
− | <syntaxhighlight> | + | ==Excel beenden und den Speicher freigeben== |
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
... | ... | ||
varXLApp.Quit; | varXLApp.Quit; | ||
− | varXLApp := | + | varXLApp := UnAssigned; //Der Speicher muss am Ende wieder freigegeben werden, sonst entstehen Speicherlecks |
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | + | ==Excel Version ermitteln== | |
− | =Excel Version ermitteln= | + | <syntaxhighlight lang=pascal> |
− | <syntaxhighlight> | ||
begin | begin | ||
... | ... | ||
Line 44: | Line 58: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | + | ==Fehlermeldungen und Warnungen deaktivieren== | |
− | = | + | Das Dekativieren von bestimmten Fehlermeldungen und Warnungen kann die Softwaresteuerung vereinfachen. |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
− | varXLApp. | + | varXLApp.DisplayAlerts := False; // schaltet diverse Fehlermeldungen von Excel aus |
− | |||
− | |||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | + | ==Sichtbarkeit von Excel steuern== | |
− | =Excel | + | Für Excel 2003 und älter gilt, dass das Unterdrücken der Anzeige die Verarbeitungsgeschwindigkeit beschleunigt.<br> |
− | + | Für alle Excelversionen gilt, dass es das das Flackern des Bildschirms verhindert. | |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
− | varXLApp. | + | varXLApp.Visible := False; // macht Excel unsichtbar |
+ | varXLApp.ScreenUpdating := False; // schaltet das ScreenUpdating von Excel aus | ||
+ | |||
+ | varXLApp.ScreenUpdating := True; // schaltet das ScreenUpdating von Excel ein | ||
+ | varXLApp.Visible := True; // macht Excel sichtbar | ||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | |
− | + | =Workbooks= | |
− | <syntaxhighlight> | + | ==Workbook (Datei) öffnen== |
+ | Öffnet eine vorhandene Datei.<br> | ||
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
... | ... | ||
− | varXLApp. | + | varXLApp.Workbooks.Open(strPfad); // öffnet die Exceldatei (Pfad: maximal 255 Zeichen) |
− | |||
− | + | // Alternative: | |
− | + | // öffnet ein vorhandenes Workbook (Exceldatei) und weist seine Speicheradresse | |
+ | // der Variablen varXLWb zu. Diese Variable ermöglicht eine kürzere Schreibweise | ||
+ | // und eindeutige (direkte) Ansprache des Dokuments. | ||
+ | // Das ist besonders dann hilfreich, wenn man mit mehreren Exceldateien gleichzeitig arbeitet. | ||
+ | varXLWb := varXLApp.Workbooks.Open(strPfad); | ||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Workbook (Datei) einfügen== |
− | <syntaxhighlight> | + | Erstellt eine neue Datei.<br> |
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
... | ... | ||
Line 90: | Line 112: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Workbook speichern== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 100: | Line 122: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Workbook unter neuem Namen speichern== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 109: | Line 131: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Workbook schliessen== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
+ | begin | ||
+ | ... | ||
+ | varXLApp.Workbooks[1].Close; | ||
+ | ... | ||
+ | end; | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | ==Name des aktiven Workbooks ermitteln== | ||
+ | <syntaxhighlight lang=pascal> | ||
+ | var | ||
+ | strName: String; | ||
+ | begin | ||
+ | ... | ||
+ | // Ausgabe am Bildschirm | ||
+ | ShowMessage(varXLApp.ActiveWorkbook.Name); | ||
+ | // Alternative: | ||
+ | // speichern in einer Variable | ||
+ | strName := varXLApp.ActiveWorkbook.Name; | ||
+ | ... | ||
+ | end; | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | =Worksheets= | ||
+ | ==Worksheet einfügen== | ||
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
... | ... | ||
Line 118: | Line 166: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Worksheet umbenennen== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 128: | Line 176: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Worksheet löschen== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 138: | Line 186: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Worksheet aktivieren== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
− | + | varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Activate; | |
− | varXLApp. | ||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Hintergrundbild einfügen== |
− | <syntaxhighlight> | + | Um ein Hintergrundbild in ein Worksheet einzufügen gibt es mehrere Möglichkeiten.<br> |
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
... | ... | ||
− | // | + | // Um das richtige Worksheet zu addressieren verwendet man den Index von Workbook und Worksheet |
− | varXLApp.WorkBooks[1].WorkSheets[1]. | + | varXLApp.WorkBooks[1].WorkSheets[1].SetBackGroundPicture('D:\Testbild.JPG'); |
+ | // Alternative | ||
+ | // Um das richtige Worksheet zu addressieren verwendet man die Namen von Workbook und Worksheet | ||
+ | varXLApp.WorkBooks['Test.xls'].WorkSheets['Tabelle2'].SetBackGroundPicture('D:\Testbild.JPG'); | ||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | |
− | <syntaxhighlight> | + | =Zeilen und Spalten= |
+ | ==Zeilenbreite und Spaltenhöhe setzen== | ||
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
... | ... | ||
Line 175: | Line 228: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Zeilen löschen== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
+ | begin | ||
+ | ... | ||
+ | // Löscht die Zeilen 8 bis 10 und verschiebt die darunter liegenden Zeilen nach oben | ||
+ | varXLWb.Worksheets['Tabelle2'].Rows['8:10'].Delete (xlUp); | ||
+ | ... | ||
+ | end; | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | =Zellen und Ranges= | ||
+ | ==Autofilter setzen== | ||
+ | <syntaxhighlight lang=pascal> | ||
+ | begin | ||
+ | ... | ||
+ | // setzt den Autofilter auf die erste Zeile | ||
+ | varXLApp.WorkBooks[1].WorkSheets[1].Rows.Rows[1].AutoFilter; | ||
+ | ... | ||
+ | end; | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | ==Rahmen zeichnen== | ||
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
... | ... | ||
Line 186: | Line 261: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Hyperlinks und URLS einfügen== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 203: | Line 278: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Wert einfügen== |
− | <syntaxhighlight> | + | Um einen oder mehrere Werte in einen Bereich einzufügen gibt es verschiedene Möglichkeiten.<br> |
+ | <syntaxhighlight lang=pascal> | ||
begin | begin | ||
− | + | ... | |
− | + | // Alternative 1 | |
− | + | varXLApp.WorkBooks[1].WorkSheets[1].Range['A5'].Value := 3; | |
+ | varXLApp.WorkBooks[1].WorkSheets[1].Range['A6'].Value := 3; | ||
+ | varXLApp.WorkBooks[1].WorkSheets[1].Range['A7'].Value := 3; | ||
+ | |||
+ | // Alternative 2 | ||
+ | varXLApp.WorkBooks[1].WorkSheets[1].Range['A5', 'A7'].Value := 3; | ||
+ | |||
+ | // Alternative 3 | ||
+ | wstrRange := UTF8ToUTF16('A' + IntToStr(5) + ':A' + IntToStr(7)); | ||
+ | varXLApp.WorkBooks[1].WorkSheets[1].Range[wstrRange].Value := 3; | ||
+ | |||
+ | // Alternative 4 | ||
+ | varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Range['A5', 'A7'].Value := 3; | ||
+ | |||
+ | // Alternative ... | ||
+ | ... | ||
+ | |||
+ | // Übernimmt Umlaute usw. und benötigt dafür die Unit lclproc | ||
+ | varXLApp.WorkSheets[1].Range['A15'].Value := UTF8ToUTF16('Überlegung'); | ||
+ | // Diese Vorgehensweise zur Verwendung von Umlauten ist sicherer | ||
+ | wstrUebergabe := UTF8ToUTF16('Überlegung'); | ||
+ | varXLApp.WorkSheets[1].Range['A15'].Value := wstrUebergabe; | ||
+ | |||
+ | // Ermittelt die letzte Zeile und schreibt diese in Zeile 1 der Spalte F | ||
+ | varXLWb.Worksheets['Tabelle2'].Range['F1'].Value := | ||
+ | varXLWb.Worksheets['Tabelle2'].UsedRange.SpecialCells(xlCellTypeLastCell).Row; | ||
+ | // schreibt Text in die Zeile 1 der Spalte B | ||
+ | varXLWb.Worksheets['Tabelle2'].Cells[1, 2].Value := 'Test'; | ||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | + | ||
− | + | ==Formel einfügen== | |
− | + | <syntaxhighlight lang=pascal> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | < | ||
− | |||
− | |||
− | |||
begin | begin | ||
... | ... | ||
Line 242: | Line 329: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | = | + | ==Arbeiten mit Schriften== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 260: | Line 347: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | + | ||
− | + | =Chart erstellen= | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | = | ||
Die Beispiele gehen davon aus, dass das Excelobjekt (varXLApp) bereits existiert und die Exceldatei geöffnet ist. | Die Beispiele gehen davon aus, dass das Excelobjekt (varXLApp) bereits existiert und die Exceldatei geöffnet ist. | ||
<br> | <br> | ||
==Chart Speicher reservieren== | ==Chart Speicher reservieren== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
var | var | ||
varDiagramm: OleVariant; | varDiagramm: OleVariant; | ||
Line 279: | Line 358: | ||
<br> | <br> | ||
==Chart Speicher freigeben== | ==Chart Speicher freigeben== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
− | varDiagramm := | + | varDiagramm := UnAssigned; |
... | ... | ||
end; | end; | ||
Line 288: | Line 367: | ||
<br> | <br> | ||
==Chart Objekt erstellen== | ==Chart Objekt erstellen== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 297: | Line 376: | ||
<br> | <br> | ||
==Chart aktivieren== | ==Chart aktivieren== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 306: | Line 385: | ||
<br> | <br> | ||
==Chart Diagramtyp festlegen== | ==Chart Diagramtyp festlegen== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 315: | Line 394: | ||
<br> | <br> | ||
==Chart Datenherkunft (Datenquelle) festlegen== | ==Chart Datenherkunft (Datenquelle) festlegen== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 324: | Line 403: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
− | ==Chart verschieben | + | ==Chart verschieben== |
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
Line 334: | Line 413: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
+ | |||
==Chart Titel== | ==Chart Titel== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
... | ... | ||
− | varXLApp.Worksheets[1].ChartObjects[1].Chart.HasTitle := True; | + | varXLApp.Worksheets[1].ChartObjects[1].Chart.HasTitle := True; // Legt fest, dass das Chart einen Titel haben darf |
varXLApp.Worksheets[1].ChartObjects[1].Chart.ChartTitle | varXLApp.Worksheets[1].ChartObjects[1].Chart.ChartTitle | ||
.Characters.Text := 'Test'; // Legt den Namen des Chart Titels fest | .Characters.Text := 'Test'; // Legt den Namen des Chart Titels fest | ||
Line 349: | Line 429: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
+ | |||
==Chart Achsenbeschriftung== | ==Chart Achsenbeschriftung== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
− | + | ... | |
− | + | // Legt fest, dass das Chart Achsen hat | |
− | + | varXLApp.Worksheets[1].ChartObjects[1].Chart.HasAxis(xlCategory) := True; | |
− | + | ||
− | + | // Legt die Schriftfarbe der Achsenkategorie fest | |
− | + | varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlCategory).TickLabels | |
− | + | .Font.Color := vbBlue; | |
− | + | ||
− | + | // Legt fest, dass das Chart eine Achsenbeschriftung haben darf | |
− | + | varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlValue).HasTitle:= True; | |
− | + | ||
+ | // Legt den Achsentitel fest | ||
+ | // Ermöglicht das Schreiben des Eurozeichens | ||
+ | varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes[xlValue].AxisTitle | ||
+ | .Characters.Text := UTF8ToUTF16('€'); | ||
+ | |||
+ | // Diese Schreibweise des Eurozeichens ist sicherer | ||
+ | wstrUebergabe := UTF8ToUTF16('€'); | ||
+ | varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes[xlValue].AxisTitle | ||
+ | .Characters.Text := wstrUebergabe; | ||
+ | |||
+ | |||
+ | // Legt die Schriftfarbe des Achsentitels fest | ||
+ | varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlValue).AxisTitle | ||
+ | .Font.Color := vbBlue; | ||
+ | |||
+ | // Legt die Schriftgrösse des Achsentitels fest | ||
+ | varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlValue).AxisTitle | ||
+ | .Font.Size := 12; | ||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<br> | <br> | ||
+ | |||
==Chart Legende== | ==Chart Legende== | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
begin | begin | ||
− | + | ... | |
− | + | //Legt die Beschriftung des ersten Elements der Chartlegende fest | |
− | + | varXLApp.Worksheets[1].ChartObjects[1].Chart.SeriesCollection(1) | |
+ | .Name := '="Eins"'; | ||
... | ... | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | < | + | |
− | + | =Auszug aus den Excelkonstanten= | |
− | -- | + | <syntaxhighlight lang=pascal> |
− | [[Category: | + | unit uXLConst; |
+ | |||
+ | interface | ||
+ | |||
+ | const | ||
+ | // Klasse XlSheetType | ||
+ | xlChart = -4109; | ||
+ | xlDialogSheet = -4116; | ||
+ | xlExcel4IntlMacroSheet = 4; | ||
+ | xlExcel4MacroSheet = 3; | ||
+ | xlWorksheet = -4167; | ||
+ | |||
+ | // Klasse XlWBATemplate | ||
+ | xlWBATChart = -4109; | ||
+ | xlWBATExcel4IntlMacroSheet = 4; | ||
+ | xlWBATExcel4MacroSheet = 3; | ||
+ | xlWBATWorksheet = -4167; | ||
+ | |||
+ | // Klasse XlPattern | ||
+ | xlPatternAutomatic = -4105; | ||
+ | xlPatternChecker = 9; | ||
+ | xlPatternCrissCross = 16; | ||
+ | xlPatternDown = -4121; | ||
+ | xlPatternGray16 = 17; | ||
+ | xlPatternGray25 = -4124; | ||
+ | xlPatternGray50 = -4125; | ||
+ | xlPatternGray75 = -4126; | ||
+ | xlPatternGray8 = 18; | ||
+ | xlPatternGrid = 15; | ||
+ | xlPatternHorizontal = -4128; | ||
+ | xlPatternLightDown = 13; | ||
+ | xlPatternLightHorizontal = 11; | ||
+ | xlPatternLightUp = 14; | ||
+ | xlPatternLightVertical = 12; | ||
+ | xlPatternNone = -4142; | ||
+ | xlPatternSemiGray75 = 10; | ||
+ | xlPatternSolid = 1; | ||
+ | xlPatternUp = -4162; | ||
+ | xlUp = -4162; | ||
+ | xlPatternVertical = -4166; | ||
+ | |||
+ | // Klasse XlBordersIndex | ||
+ | xlInsideHorizontal = 12; | ||
+ | xlInsideVertical = 11; | ||
+ | xlDiagonalDown = 5; | ||
+ | xlDiagonalUp = 6; | ||
+ | xlEdgeBottom = 9; | ||
+ | xlEdgeLeft = 7; | ||
+ | xlEdgeRight = 10; | ||
+ | xlEdgeTop = 8; | ||
+ | |||
+ | // Klasse XlLineStyle | ||
+ | xlContinuous = 1; | ||
+ | xlDash = -4115; | ||
+ | xlDashDot = 4; | ||
+ | xlDashDotDot = 5; | ||
+ | xlDot = -4118; | ||
+ | xlDouble = -4119; | ||
+ | xlSlantDashDot = 13; | ||
+ | xlLineStyleNone = -4142; | ||
+ | |||
+ | // Klasse XlChartType | ||
+ | xlColumnClustered = 51; | ||
+ | xlColumnStacked = 52; | ||
+ | xlColumnStacked100 = 53; | ||
+ | xl3DColumnClustered = 54; | ||
+ | xl3DColumnStacked = 55; | ||
+ | xl3DColumnStacked100 = 56; | ||
+ | xlBarClustered = 57; | ||
+ | xlBarStacked = 58; | ||
+ | xlBarStacked100 = 59; | ||
+ | xl3DBarClustered = 60; | ||
+ | xl3DBarStacked = 61; | ||
+ | xl3DBarStacked100 = 62; | ||
+ | xlLineStacked = 63; | ||
+ | xlLineStacked100 = 64; | ||
+ | xlLineMarkers = 65; | ||
+ | xlLineMarkersStacked = 66; | ||
+ | xlLineMarkersStacked100 = 67; | ||
+ | xlPieOfPie = 68; | ||
+ | xlPieExploded = 69; | ||
+ | xl3DPieExploded = 70; | ||
+ | xlBarOfPie = 71; | ||
+ | xlXYScatterSmooth = 72; | ||
+ | xlXYScatterSmoothNoMarkers = 73; | ||
+ | xlXYScatterLines = 74; | ||
+ | xlXYScatterLinesNoMarkers = 75; | ||
+ | xlAreaStacked = 76; | ||
+ | xlAreaStacked100 = 77; | ||
+ | xl3DAreaStacked = 78; | ||
+ | xl3DAreaStacked100 = 79; | ||
+ | xlDoughnutExploded = 80; | ||
+ | xlRadarMarkers = 81; | ||
+ | xlRadarFilled = 82; | ||
+ | xlSurface = 83; | ||
+ | xlSurfaceWireframe = 84; | ||
+ | xlSurfaceTopView = 85; | ||
+ | xlSurfaceTopViewWireframe = 86; | ||
+ | xlBubble = 15; | ||
+ | xlBubble3DEffect = 87; | ||
+ | xlStockHLC = 88; | ||
+ | xlStockOHLC = 89; | ||
+ | xlStockVHLC = 90; | ||
+ | xlStockVOHLC = 91; | ||
+ | xlCylinderColClustered = 92; | ||
+ | xlCylinderColStacked = 93; | ||
+ | xlCylinderColStacked100 = 94; | ||
+ | xlCylinderBarClustered = 95; | ||
+ | xlCylinderBarStacked = 96; | ||
+ | xlCylinderBarStacked100 = 97; | ||
+ | xlCylinderCol = 98; | ||
+ | xlConeColClustered = 99; | ||
+ | xlConeColStacked = 100; | ||
+ | xlConeColStacked100 = 101; | ||
+ | xlConeBarClustered = 102; | ||
+ | xlConeBarStacked = 103; | ||
+ | xlConeBarStacked100 = 104; | ||
+ | xlConeCol = 105; | ||
+ | xlPyramidColClustered = 106; | ||
+ | xlPyramidColStacked = 107; | ||
+ | xlPyramidColStacked100 = 108; | ||
+ | xlPyramidBarClustered = 109; | ||
+ | xlPyramidBarStacked = 110; | ||
+ | xlPyramidBarStacked100 = 111; | ||
+ | xlPyramidCol = 112; | ||
+ | xl3DColumn = -4100; | ||
+ | xlLine = 4; | ||
+ | xl3DLine = -4101; | ||
+ | xl3DPie = -4102; | ||
+ | xlPie = 5; | ||
+ | xlXYScatter = -4169; | ||
+ | xl3DArea = -4098; | ||
+ | xlArea = 1; | ||
+ | xlDoughnut = -4120; | ||
+ | xlRadar = -4151; | ||
+ | |||
+ | // Klasse Constants | ||
+ | xlAll = -4104; | ||
+ | xlAutomatic = -4105; | ||
+ | xlBoth = 1; | ||
+ | xlCenter = -4108; | ||
+ | xlChecker = 9; | ||
+ | xlCircle = 8; | ||
+ | xlCorner = 2; | ||
+ | xlCrissCross = 16; | ||
+ | xlCross = 4; | ||
+ | xlDiamond = 2; | ||
+ | xlDistributed = -4117; | ||
+ | xlDoubleAccounting = 5; | ||
+ | xlFixedValue = 1; | ||
+ | xlFormats = -4122; | ||
+ | xlGray16 = 17; | ||
+ | xlGray8 = 18; | ||
+ | xlGrid = 15; | ||
+ | xlHigh = -4127; | ||
+ | xlInside = 2; | ||
+ | xlJustify = -4130; | ||
+ | xlLightDown = 13; | ||
+ | xlLightHorizontal = 11; | ||
+ | xlLightUp = 14; | ||
+ | xlLightVertical = 12; | ||
+ | xlLow = -4134; | ||
+ | xlManual = -4135; | ||
+ | xlMinusValues = 3; | ||
+ | xlModule = -4141; | ||
+ | xlNextToAxis = 4; | ||
+ | xlNone = -4142; | ||
+ | xlNotes = -4144; | ||
+ | xlOff = -4146; | ||
+ | xlOn = 1; | ||
+ | xlPercent = 2; | ||
+ | xlPlus = 9; | ||
+ | xlPlusValues = 2; | ||
+ | xlSemiGray75 = 10; | ||
+ | xlShowLabel = 4; | ||
+ | xlShowLabelAndPercent = 5; | ||
+ | xlShowPercent = 3; | ||
+ | xlShowValue = 2; | ||
+ | xlSimple = -4154; | ||
+ | xlSingle = 2; | ||
+ | xlSingleAccounting = 4; | ||
+ | xlSolid = 1; | ||
+ | xlSquare = 1; | ||
+ | xlStar = 5; | ||
+ | xlStError = 4; | ||
+ | xlToolbarButton = 2; | ||
+ | xlTriangle = 3; | ||
+ | xlGray25 = -4124; | ||
+ | xlGray50 = -4125; | ||
+ | xlGray75 = -4126; | ||
+ | xlBottom = -4107; | ||
+ | xlLeft = -4131; | ||
+ | xlRight = -4152; | ||
+ | xlTop = -4160; | ||
+ | xl3DBar = -4099; | ||
+ | xl3DSurface = -4103; | ||
+ | xlBar = 2; | ||
+ | xlColumn = 3; | ||
+ | xlCombination = -4111; | ||
+ | xlCustom = -4114; | ||
+ | xlDefaultAutoFormat = -1; | ||
+ | xlMaximum = 2; | ||
+ | xlMinimum = 4; | ||
+ | xlOpaque = 3; | ||
+ | xlTransparent = 2; | ||
+ | xlBidi = -5000; | ||
+ | xlLatin = -5001; | ||
+ | xlContext = -5002; | ||
+ | xlLTR = -5003; | ||
+ | xlRTL = -5004; | ||
+ | xlVisualCursor = 2; | ||
+ | xlLogicalCursor = 1; | ||
+ | xlSystem = 1; | ||
+ | xlPartial = 3; | ||
+ | xlHindiNumerals = 3; | ||
+ | xlBidiCalendar = 3; | ||
+ | xlGregorian = 2; | ||
+ | xlComplete = 4; | ||
+ | xlScale = 3; | ||
+ | xlClosed = 3; | ||
+ | xlColor1 = 7; | ||
+ | xlColor2 = 8; | ||
+ | xlColor3 = 9; | ||
+ | xlConstants = 2; | ||
+ | xlContents = 2; | ||
+ | xlBelow = 1; | ||
+ | xlCascade = 7; | ||
+ | xlCenterAcrossSelection = 7; | ||
+ | xlChart4 = 2; | ||
+ | xlChartSeries = 17; | ||
+ | xlChartShort = 6; | ||
+ | xlChartTitles = 18; | ||
+ | xlClassic1 = 1; | ||
+ | xlClassic2 = 2; | ||
+ | xlClassic3 = 3; | ||
+ | xl3DEffects1 = 13; | ||
+ | xl3DEffects2 = 14; | ||
+ | xlAbove = 0; | ||
+ | xlAccounting1 = 4; | ||
+ | xlAccounting2 = 5; | ||
+ | xlAccounting3 = 6; | ||
+ | xlAccounting4 = 17; | ||
+ | xlAdd = 2; | ||
+ | xlDebugCodePane = 13; | ||
+ | xlDesktop = 9; | ||
+ | xlDirect = 1; | ||
+ | xlDivide = 5; | ||
+ | xlDoubleClosed = 5; | ||
+ | xlDoubleOpen = 4; | ||
+ | xlDoubleQuote = 1; | ||
+ | xlEntireChart = 20; | ||
+ | xlExcelMenus = 1; | ||
+ | xlExtended = 3; | ||
+ | xlFill = 5; | ||
+ | xlFirst = 0; | ||
+ | xlFloating = 5; | ||
+ | xlFormula = 5; | ||
+ | xlGeneral = 1; | ||
+ | xlGridline = 22; | ||
+ | xlIcons = 1; | ||
+ | xlImmediatePane = 12; | ||
+ | xlInteger = 2; | ||
+ | xlLast = 1; | ||
+ | xlLastCell = 11; | ||
+ | xlList1 = 10; | ||
+ | xlList2 = 11; | ||
+ | xlList3 = 12; | ||
+ | xlLocalFormat1 = 15; | ||
+ | xlLocalFormat2 = 16; | ||
+ | xlLong = 3; | ||
+ | xlLotusHelp = 2; | ||
+ | xlMacrosheetCell = 7; | ||
+ | xlMixed = 2; | ||
+ | xlMultiply = 4; | ||
+ | xlNarrow = 1; | ||
+ | xlNoDocuments = 3; | ||
+ | xlOpen = 2; | ||
+ | xlOutside = 3; | ||
+ | xlReference = 4; | ||
+ | xlSemiautomatic = 2; | ||
+ | xlShort = 1; | ||
+ | xlSingleQuote = 2; | ||
+ | xlStrict = 2; | ||
+ | xlSubtract = 3; | ||
+ | xlTextBox = 16; | ||
+ | xlTiled = 1; | ||
+ | xlTitleBar = 8; | ||
+ | xlToolbar = 1; | ||
+ | xlVisible = 12; | ||
+ | xlWatchPane = 11; | ||
+ | xlWide = 3; | ||
+ | xlWorkbookTab = 6; | ||
+ | xlWorksheet4 = 1; | ||
+ | xlWorksheetCell = 3; | ||
+ | xlWorksheetShort = 5; | ||
+ | xlAllExceptBorders = 6; | ||
+ | xlLeftToRight = 2; | ||
+ | xlTopToBottom = 1; | ||
+ | xlVeryHidden = 2; | ||
+ | xlDrawingObject = 14; | ||
+ | |||
+ | // Klasse XLPlacement | ||
+ | xlMoveAndSize = 1; | ||
+ | xlMove = 2; | ||
+ | xlFreeFloating = 3; | ||
+ | |||
+ | // Klasse XlRowCol | ||
+ | xlRows = 1; | ||
+ | xlColumns = 2; | ||
+ | |||
+ | // Klasse XlChartLocation | ||
+ | xlLocationAsNewSheet = 1; | ||
+ | xlLocationAsObject = 2; | ||
+ | xlLocationAutomatic = 3; | ||
+ | |||
+ | // Klasse XlAxisType | ||
+ | xlCategory = 1; | ||
+ | xlValue = 2; | ||
+ | xlSeriesAxis = 3; | ||
+ | |||
+ | // Klasse ColorConstants | ||
+ | vbBlack = 0; | ||
+ | vbBlue = 16711680; | ||
+ | vbCyan = 16776960; | ||
+ | vbGreen = 65280; | ||
+ | vbMagenta = 16711935; | ||
+ | vbRed = 255; | ||
+ | vbWhite = 16777215; | ||
+ | vbYellow = 65535; | ||
+ | |||
+ | // Klasse XlCellType | ||
+ | xlCellTypeAllFormatConditions = -4172; | ||
+ | xlCellTypeAllValidation = -4174; | ||
+ | xlCellTypeBlanks = 4; | ||
+ | xlCellTypeComments = -4144; | ||
+ | xlCellTypeConstants = 2; | ||
+ | xlCellTypeFormulas = -4123; | ||
+ | xlCellTypeLastCell = 11; | ||
+ | xlCellTypeSameFormatConditions = -4173; | ||
+ | xlCellTypeSameValidation = -4175; | ||
+ | xlCellTypeVisible = 12; | ||
+ | |||
+ | // Klasse XLAxisGroup | ||
+ | xlPrimary = 1; | ||
+ | xlSecondary = 2; | ||
+ | |||
+ | implementation | ||
+ | |||
+ | end. | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | [[Category:Tutorials/de]] |
Latest revision as of 14:05, 14 February 2020
Deutsch (de)
Zurück zur Office Automation.
Excel
Alle Möglichkeiten der Excelautomation aufzuzeigen ist nicht möglich ich hoffe aber für jeden Bedarf Anregungen gefunden zu haben.
Excel ist zu dem die automatisierungsfreundlichste Software von Microsoft.
Wenn Sie Umlaute usw. verwenden, dann sollten Sie wissen, dass Excel UTF16 codierte Strings verwendet.
Für die Oleautomation muss die Unit ComObj eingebunden werden.
Für die Verwendung von Umlauten usw. muss die Unit lclproc eingebunden werden.
Speicherplatz reservieren
var
varXLApp: oleVariant; // wird für die Adressierung des Programms Excel verwedet
varXLWb: oleVariant; // wird für die Adressierung des Exceldatei verwendet
wstrUebergabe: WideString; // Hilfsvariable (wird z. B. für Umlaute usw. benötigt)
wstrRange: WideString // Hilfsvariable für eine Range
Excel OleObjekt erstellen
uses
comobj;
begin
...
try
varXLApp := CreateOleObject('Excel.Application'); // erstellt das Excelobjekt
except
WriteLn('MS Excel kann nicht gestartet werden.'); // Fehlerbehandlung
end;
...
end;
Excel beenden und den Speicher freigeben
begin
...
varXLApp.Quit;
varXLApp := UnAssigned; //Der Speicher muss am Ende wieder freigegeben werden, sonst entstehen Speicherlecks
...
end;
Excel Version ermitteln
begin
...
ShowMessage(varXLApp.Version);
...
end;
Fehlermeldungen und Warnungen deaktivieren
Das Dekativieren von bestimmten Fehlermeldungen und Warnungen kann die Softwaresteuerung vereinfachen.
begin
...
varXLApp.DisplayAlerts := False; // schaltet diverse Fehlermeldungen von Excel aus
...
end;
Sichtbarkeit von Excel steuern
Für Excel 2003 und älter gilt, dass das Unterdrücken der Anzeige die Verarbeitungsgeschwindigkeit beschleunigt.
Für alle Excelversionen gilt, dass es das das Flackern des Bildschirms verhindert.
begin
...
varXLApp.Visible := False; // macht Excel unsichtbar
varXLApp.ScreenUpdating := False; // schaltet das ScreenUpdating von Excel aus
varXLApp.ScreenUpdating := True; // schaltet das ScreenUpdating von Excel ein
varXLApp.Visible := True; // macht Excel sichtbar
...
end;
Workbooks
Workbook (Datei) öffnen
Öffnet eine vorhandene Datei.
begin
...
varXLApp.Workbooks.Open(strPfad); // öffnet die Exceldatei (Pfad: maximal 255 Zeichen)
// Alternative:
// öffnet ein vorhandenes Workbook (Exceldatei) und weist seine Speicheradresse
// der Variablen varXLWb zu. Diese Variable ermöglicht eine kürzere Schreibweise
// und eindeutige (direkte) Ansprache des Dokuments.
// Das ist besonders dann hilfreich, wenn man mit mehreren Exceldateien gleichzeitig arbeitet.
varXLWb := varXLApp.Workbooks.Open(strPfad);
...
end;
Workbook (Datei) einfügen
Erstellt eine neue Datei.
begin
...
varXLApp.Workbooks.Add; // fügt ein neues Workbook ein
...
end;
Workbook speichern
begin
...
varXLApp.Workbooks[1].Save; // speichert ein Worksheet über seinen Index
varXLApp.Workbooks['Test.xls'].Save; // speicher ein Worksheet über seinen Namen
...
end;
Workbook unter neuem Namen speichern
begin
...
varXLApp.Workbooks[1].SaveAs('D:\Test.xls', varXLApp.Workbooks[1].fileformat);
...
end;
Workbook schliessen
begin
...
varXLApp.Workbooks[1].Close;
...
end;
Name des aktiven Workbooks ermitteln
var
strName: String;
begin
...
// Ausgabe am Bildschirm
ShowMessage(varXLApp.ActiveWorkbook.Name);
// Alternative:
// speichern in einer Variable
strName := varXLApp.ActiveWorkbook.Name;
...
end;
Worksheets
Worksheet einfügen
begin
...
varXLApp.WorkBooks[1].WorkSheets.Add; //fügt ein neues WorkSheet hinzu
...
end;
Worksheet umbenennen
begin
...
varXLApp.WorkBooks[1].WorkSheets[1].Name := 'Neuer Name'; // benennt ein Worksheet über seinen Index um
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Name := 'Neuer Name'; // benennt ein Worksheet über seinen Namen um
...
end;
Worksheet löschen
begin
...
varXLApp.WorkBooks[1].WorkSheets[3].Delete; // löscht ein Worksheet über seinen Index
varXLApp.WorkBooks[1].WorkSheets['Tabelle3'].Delete; // löscht ein Worksheet über seinen Namen
...
end;
Worksheet aktivieren
begin
...
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Activate;
...
end;
Hintergrundbild einfügen
Um ein Hintergrundbild in ein Worksheet einzufügen gibt es mehrere Möglichkeiten.
begin
...
// Um das richtige Worksheet zu addressieren verwendet man den Index von Workbook und Worksheet
varXLApp.WorkBooks[1].WorkSheets[1].SetBackGroundPicture('D:\Testbild.JPG');
// Alternative
// Um das richtige Worksheet zu addressieren verwendet man die Namen von Workbook und Worksheet
varXLApp.WorkBooks['Test.xls'].WorkSheets['Tabelle2'].SetBackGroundPicture('D:\Testbild.JPG');
...
end;
Zeilen und Spalten
Zeilenbreite und Spaltenhöhe setzen
begin
...
// Setzt die Spaltenbreite für Spalte 1
varXLApp.WorkBooks[1].WorkSheets[1].Columns.Columns[1].ColumnWidth := 70;
// oder
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Columns.Columns[1].ColumnWidth := 70;
// Setzt die Spaltenhöhe für Zeile 1
varXLApp.WorkBooks[1].WorkSheets[1].Rows.Rows[1].RowHeight := 60;
// oder
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Rows.Rows[1].RowHeight := 60;
...
end;
Zeilen löschen
begin
...
// Löscht die Zeilen 8 bis 10 und verschiebt die darunter liegenden Zeilen nach oben
varXLWb.Worksheets['Tabelle2'].Rows['8:10'].Delete (xlUp);
...
end;
Zellen und Ranges
Autofilter setzen
begin
...
// setzt den Autofilter auf die erste Zeile
varXLApp.WorkBooks[1].WorkSheets[1].Rows.Rows[1].AutoFilter;
...
end;
Rahmen zeichnen
begin
...
// Zeichnet einen Rahmen um den Bereich "B2:C3"
// Der Parameter BorderAround hat folgende Syntax: BorderAround(Linienstil, Linenstärke, Farbe)
varXLApp.WorkBooks[1].WorkSheets[1].Range['B2:C3'].BorderAround(1, 2, 1);
...
end;
Hyperlinks und URLS einfügen
begin
...
// Fügt eine URL in Zelle "A2" in Sheet 2 ein
// Alternative 1
varXLApp.WorkBooks[1].Worksheets[2].Hyperlinks.add(
varXLApp.WorkBooks[1].Worksheets[2].Cells[2, 1], 'http://www.google.de');
// Alternative 2
varXLApp.WorkBooks[1].worksheets[2].Cells[2,1].Formula := '=HYPERLINK("http://www.google.de")';
// Fügt eine Emailadresse als Formel in Zelle "A3" in Sheet 2 ein
varXLApp.WorkBooks[1].worksheets[2].Cells[3,1].Formula := '=HYPERLINK("mailto:test.testmann.@test.com","Email")';
...
end;
Wert einfügen
Um einen oder mehrere Werte in einen Bereich einzufügen gibt es verschiedene Möglichkeiten.
begin
...
// Alternative 1
varXLApp.WorkBooks[1].WorkSheets[1].Range['A5'].Value := 3;
varXLApp.WorkBooks[1].WorkSheets[1].Range['A6'].Value := 3;
varXLApp.WorkBooks[1].WorkSheets[1].Range['A7'].Value := 3;
// Alternative 2
varXLApp.WorkBooks[1].WorkSheets[1].Range['A5', 'A7'].Value := 3;
// Alternative 3
wstrRange := UTF8ToUTF16('A' + IntToStr(5) + ':A' + IntToStr(7));
varXLApp.WorkBooks[1].WorkSheets[1].Range[wstrRange].Value := 3;
// Alternative 4
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Range['A5', 'A7'].Value := 3;
// Alternative ...
...
// Übernimmt Umlaute usw. und benötigt dafür die Unit lclproc
varXLApp.WorkSheets[1].Range['A15'].Value := UTF8ToUTF16('Überlegung');
// Diese Vorgehensweise zur Verwendung von Umlauten ist sicherer
wstrUebergabe := UTF8ToUTF16('Überlegung');
varXLApp.WorkSheets[1].Range['A15'].Value := wstrUebergabe;
// Ermittelt die letzte Zeile und schreibt diese in Zeile 1 der Spalte F
varXLWb.Worksheets['Tabelle2'].Range['F1'].Value :=
varXLWb.Worksheets['Tabelle2'].UsedRange.SpecialCells(xlCellTypeLastCell).Row;
// schreibt Text in die Zeile 1 der Spalte B
varXLWb.Worksheets['Tabelle2'].Cells[1, 2].Value := 'Test';
...
end;
Formel einfügen
begin
...
// Alternative 1
varXLApp.WorkBooks[1].worksheets[2].Cells[6,3].Formula := '=Sum(A5:A7)';
// Alternative 2
varXLApp.WorkBooks[1].WorkSheets[2].Range['C6'].Formula := '=Sum(A5:A7)';
...
end;
Arbeiten mit Schriften
begin
...
// Legt die Schriftart fest
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Cells[1, 1].Font.Name := 'Arial';
// Legt die Schriftgröße fest
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Cells[1, 1].Font.Size := 20;
// Legt die Fettschrift fest
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Cells[1, 1].Font.Bold := True;
//Legt die Kursivschrift fest
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Cells[1, 1].Font.Italic := True;
// Unterstreicht den Eintrag
varXLApp.WorkBooks[1].WorkSheets['Tabelle1'].Cells[1, 1].Font.Underline := True;
...
end;
Chart erstellen
Die Beispiele gehen davon aus, dass das Excelobjekt (varXLApp) bereits existiert und die Exceldatei geöffnet ist.
Chart Speicher reservieren
var
varDiagramm: OleVariant;
Chart Speicher freigeben
begin
...
varDiagramm := UnAssigned;
...
end;
Chart Objekt erstellen
begin
...
varDiagramm := varXLApp.Charts.Add; // Fügt ein Chart ein
...
end;
Chart aktivieren
begin
...
varDiagramm.Activate; // Aktiviert das Chart
...
end;
Chart Diagramtyp festlegen
begin
...
varDiagramm.ChartType := xlColumnClustered; // Legt den Diagramtyp fest
...
end;
Chart Datenherkunft (Datenquelle) festlegen
begin
...
varDiagramm.SetSourceData (Source := varXLApp.WorkSheets['Tabelle1'].Range['A1:E13'],
PlotBy := xlColumns); // Legt die Datenherkunft (das Excelsheet und den Bereich im Excelsheet) fest
...
end;
Chart verschieben
begin
...
// Diagramm im selben Tabellenblatt wie die Datentabelle.
varDiagramm.Location (Where := xlLocationAsObject, Name:= 'Tabelle1');
...
end;
Chart Titel
begin
...
varXLApp.Worksheets[1].ChartObjects[1].Chart.HasTitle := True; // Legt fest, dass das Chart einen Titel haben darf
varXLApp.Worksheets[1].ChartObjects[1].Chart.ChartTitle
.Characters.Text := 'Test'; // Legt den Namen des Chart Titels fest
varXLApp.Worksheets[1].ChartObjects[1].Chart.ChartTitle
.Font.Color := vbRed; // Legt die Schriftfarbe des Diagrammtitels fest
varXLApp.Worksheets[1].ChartObjects[1].Chart.ChartTitle
.Interior.Color := vbCyan; // Legt die Hintergrundarbe des Diagrammtitels fest
...
end;
Chart Achsenbeschriftung
begin
...
// Legt fest, dass das Chart Achsen hat
varXLApp.Worksheets[1].ChartObjects[1].Chart.HasAxis(xlCategory) := True;
// Legt die Schriftfarbe der Achsenkategorie fest
varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlCategory).TickLabels
.Font.Color := vbBlue;
// Legt fest, dass das Chart eine Achsenbeschriftung haben darf
varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlValue).HasTitle:= True;
// Legt den Achsentitel fest
// Ermöglicht das Schreiben des Eurozeichens
varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes[xlValue].AxisTitle
.Characters.Text := UTF8ToUTF16('€');
// Diese Schreibweise des Eurozeichens ist sicherer
wstrUebergabe := UTF8ToUTF16('€');
varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes[xlValue].AxisTitle
.Characters.Text := wstrUebergabe;
// Legt die Schriftfarbe des Achsentitels fest
varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlValue).AxisTitle
.Font.Color := vbBlue;
// Legt die Schriftgrösse des Achsentitels fest
varXLApp.Worksheets[1].ChartObjects[1].Chart.Axes(xlValue).AxisTitle
.Font.Size := 12;
...
end;
Chart Legende
begin
...
//Legt die Beschriftung des ersten Elements der Chartlegende fest
varXLApp.Worksheets[1].ChartObjects[1].Chart.SeriesCollection(1)
.Name := '="Eins"';
...
end;
Auszug aus den Excelkonstanten
unit uXLConst;
interface
const
// Klasse XlSheetType
xlChart = -4109;
xlDialogSheet = -4116;
xlExcel4IntlMacroSheet = 4;
xlExcel4MacroSheet = 3;
xlWorksheet = -4167;
// Klasse XlWBATemplate
xlWBATChart = -4109;
xlWBATExcel4IntlMacroSheet = 4;
xlWBATExcel4MacroSheet = 3;
xlWBATWorksheet = -4167;
// Klasse XlPattern
xlPatternAutomatic = -4105;
xlPatternChecker = 9;
xlPatternCrissCross = 16;
xlPatternDown = -4121;
xlPatternGray16 = 17;
xlPatternGray25 = -4124;
xlPatternGray50 = -4125;
xlPatternGray75 = -4126;
xlPatternGray8 = 18;
xlPatternGrid = 15;
xlPatternHorizontal = -4128;
xlPatternLightDown = 13;
xlPatternLightHorizontal = 11;
xlPatternLightUp = 14;
xlPatternLightVertical = 12;
xlPatternNone = -4142;
xlPatternSemiGray75 = 10;
xlPatternSolid = 1;
xlPatternUp = -4162;
xlUp = -4162;
xlPatternVertical = -4166;
// Klasse XlBordersIndex
xlInsideHorizontal = 12;
xlInsideVertical = 11;
xlDiagonalDown = 5;
xlDiagonalUp = 6;
xlEdgeBottom = 9;
xlEdgeLeft = 7;
xlEdgeRight = 10;
xlEdgeTop = 8;
// Klasse XlLineStyle
xlContinuous = 1;
xlDash = -4115;
xlDashDot = 4;
xlDashDotDot = 5;
xlDot = -4118;
xlDouble = -4119;
xlSlantDashDot = 13;
xlLineStyleNone = -4142;
// Klasse XlChartType
xlColumnClustered = 51;
xlColumnStacked = 52;
xlColumnStacked100 = 53;
xl3DColumnClustered = 54;
xl3DColumnStacked = 55;
xl3DColumnStacked100 = 56;
xlBarClustered = 57;
xlBarStacked = 58;
xlBarStacked100 = 59;
xl3DBarClustered = 60;
xl3DBarStacked = 61;
xl3DBarStacked100 = 62;
xlLineStacked = 63;
xlLineStacked100 = 64;
xlLineMarkers = 65;
xlLineMarkersStacked = 66;
xlLineMarkersStacked100 = 67;
xlPieOfPie = 68;
xlPieExploded = 69;
xl3DPieExploded = 70;
xlBarOfPie = 71;
xlXYScatterSmooth = 72;
xlXYScatterSmoothNoMarkers = 73;
xlXYScatterLines = 74;
xlXYScatterLinesNoMarkers = 75;
xlAreaStacked = 76;
xlAreaStacked100 = 77;
xl3DAreaStacked = 78;
xl3DAreaStacked100 = 79;
xlDoughnutExploded = 80;
xlRadarMarkers = 81;
xlRadarFilled = 82;
xlSurface = 83;
xlSurfaceWireframe = 84;
xlSurfaceTopView = 85;
xlSurfaceTopViewWireframe = 86;
xlBubble = 15;
xlBubble3DEffect = 87;
xlStockHLC = 88;
xlStockOHLC = 89;
xlStockVHLC = 90;
xlStockVOHLC = 91;
xlCylinderColClustered = 92;
xlCylinderColStacked = 93;
xlCylinderColStacked100 = 94;
xlCylinderBarClustered = 95;
xlCylinderBarStacked = 96;
xlCylinderBarStacked100 = 97;
xlCylinderCol = 98;
xlConeColClustered = 99;
xlConeColStacked = 100;
xlConeColStacked100 = 101;
xlConeBarClustered = 102;
xlConeBarStacked = 103;
xlConeBarStacked100 = 104;
xlConeCol = 105;
xlPyramidColClustered = 106;
xlPyramidColStacked = 107;
xlPyramidColStacked100 = 108;
xlPyramidBarClustered = 109;
xlPyramidBarStacked = 110;
xlPyramidBarStacked100 = 111;
xlPyramidCol = 112;
xl3DColumn = -4100;
xlLine = 4;
xl3DLine = -4101;
xl3DPie = -4102;
xlPie = 5;
xlXYScatter = -4169;
xl3DArea = -4098;
xlArea = 1;
xlDoughnut = -4120;
xlRadar = -4151;
// Klasse Constants
xlAll = -4104;
xlAutomatic = -4105;
xlBoth = 1;
xlCenter = -4108;
xlChecker = 9;
xlCircle = 8;
xlCorner = 2;
xlCrissCross = 16;
xlCross = 4;
xlDiamond = 2;
xlDistributed = -4117;
xlDoubleAccounting = 5;
xlFixedValue = 1;
xlFormats = -4122;
xlGray16 = 17;
xlGray8 = 18;
xlGrid = 15;
xlHigh = -4127;
xlInside = 2;
xlJustify = -4130;
xlLightDown = 13;
xlLightHorizontal = 11;
xlLightUp = 14;
xlLightVertical = 12;
xlLow = -4134;
xlManual = -4135;
xlMinusValues = 3;
xlModule = -4141;
xlNextToAxis = 4;
xlNone = -4142;
xlNotes = -4144;
xlOff = -4146;
xlOn = 1;
xlPercent = 2;
xlPlus = 9;
xlPlusValues = 2;
xlSemiGray75 = 10;
xlShowLabel = 4;
xlShowLabelAndPercent = 5;
xlShowPercent = 3;
xlShowValue = 2;
xlSimple = -4154;
xlSingle = 2;
xlSingleAccounting = 4;
xlSolid = 1;
xlSquare = 1;
xlStar = 5;
xlStError = 4;
xlToolbarButton = 2;
xlTriangle = 3;
xlGray25 = -4124;
xlGray50 = -4125;
xlGray75 = -4126;
xlBottom = -4107;
xlLeft = -4131;
xlRight = -4152;
xlTop = -4160;
xl3DBar = -4099;
xl3DSurface = -4103;
xlBar = 2;
xlColumn = 3;
xlCombination = -4111;
xlCustom = -4114;
xlDefaultAutoFormat = -1;
xlMaximum = 2;
xlMinimum = 4;
xlOpaque = 3;
xlTransparent = 2;
xlBidi = -5000;
xlLatin = -5001;
xlContext = -5002;
xlLTR = -5003;
xlRTL = -5004;
xlVisualCursor = 2;
xlLogicalCursor = 1;
xlSystem = 1;
xlPartial = 3;
xlHindiNumerals = 3;
xlBidiCalendar = 3;
xlGregorian = 2;
xlComplete = 4;
xlScale = 3;
xlClosed = 3;
xlColor1 = 7;
xlColor2 = 8;
xlColor3 = 9;
xlConstants = 2;
xlContents = 2;
xlBelow = 1;
xlCascade = 7;
xlCenterAcrossSelection = 7;
xlChart4 = 2;
xlChartSeries = 17;
xlChartShort = 6;
xlChartTitles = 18;
xlClassic1 = 1;
xlClassic2 = 2;
xlClassic3 = 3;
xl3DEffects1 = 13;
xl3DEffects2 = 14;
xlAbove = 0;
xlAccounting1 = 4;
xlAccounting2 = 5;
xlAccounting3 = 6;
xlAccounting4 = 17;
xlAdd = 2;
xlDebugCodePane = 13;
xlDesktop = 9;
xlDirect = 1;
xlDivide = 5;
xlDoubleClosed = 5;
xlDoubleOpen = 4;
xlDoubleQuote = 1;
xlEntireChart = 20;
xlExcelMenus = 1;
xlExtended = 3;
xlFill = 5;
xlFirst = 0;
xlFloating = 5;
xlFormula = 5;
xlGeneral = 1;
xlGridline = 22;
xlIcons = 1;
xlImmediatePane = 12;
xlInteger = 2;
xlLast = 1;
xlLastCell = 11;
xlList1 = 10;
xlList2 = 11;
xlList3 = 12;
xlLocalFormat1 = 15;
xlLocalFormat2 = 16;
xlLong = 3;
xlLotusHelp = 2;
xlMacrosheetCell = 7;
xlMixed = 2;
xlMultiply = 4;
xlNarrow = 1;
xlNoDocuments = 3;
xlOpen = 2;
xlOutside = 3;
xlReference = 4;
xlSemiautomatic = 2;
xlShort = 1;
xlSingleQuote = 2;
xlStrict = 2;
xlSubtract = 3;
xlTextBox = 16;
xlTiled = 1;
xlTitleBar = 8;
xlToolbar = 1;
xlVisible = 12;
xlWatchPane = 11;
xlWide = 3;
xlWorkbookTab = 6;
xlWorksheet4 = 1;
xlWorksheetCell = 3;
xlWorksheetShort = 5;
xlAllExceptBorders = 6;
xlLeftToRight = 2;
xlTopToBottom = 1;
xlVeryHidden = 2;
xlDrawingObject = 14;
// Klasse XLPlacement
xlMoveAndSize = 1;
xlMove = 2;
xlFreeFloating = 3;
// Klasse XlRowCol
xlRows = 1;
xlColumns = 2;
// Klasse XlChartLocation
xlLocationAsNewSheet = 1;
xlLocationAsObject = 2;
xlLocationAutomatic = 3;
// Klasse XlAxisType
xlCategory = 1;
xlValue = 2;
xlSeriesAxis = 3;
// Klasse ColorConstants
vbBlack = 0;
vbBlue = 16711680;
vbCyan = 16776960;
vbGreen = 65280;
vbMagenta = 16711935;
vbRed = 255;
vbWhite = 16777215;
vbYellow = 65535;
// Klasse XlCellType
xlCellTypeAllFormatConditions = -4172;
xlCellTypeAllValidation = -4174;
xlCellTypeBlanks = 4;
xlCellTypeComments = -4144;
xlCellTypeConstants = 2;
xlCellTypeFormulas = -4123;
xlCellTypeLastCell = 11;
xlCellTypeSameFormatConditions = -4173;
xlCellTypeSameValidation = -4175;
xlCellTypeVisible = 12;
// Klasse XLAxisGroup
xlPrimary = 1;
xlSecondary = 2;
implementation
end.