Titel von Excel Diagrammen verwalten
In Excel-Diagrammen gibt es 2 Arten von Titeln:
- Diagrammtitel
- Achsentitel
Titeloptionen
Aspose.Cells für Python via .NET erlaubt auch die Verwaltung der Diagrammtitel zur Laufzeit, mit dem Title Objekt können Sie Text, Schriftart- und Füllformat für Titel ändern.
||
Einstellen der Titel von Diagrammen oder Achsen
Sie können Microsoft Excel verwenden, um die Titel eines Diagramms und seiner Achsen in einer WYSIWYG-Umgebung festzulegen. Aspose.Cells für Python via .NET ermöglicht auch es Entwicklern, die Titel eines Diagramms und seiner Achsen zur Laufzeit festzulegen. Alle Diagramme und ihre Achsen verfügen über eine title-Eigenschaft, mit der ihre Titel wie im Beispiel unten festgelegt werden können.
Der folgende Codeausschnitt zeigt, wie Titel für Diagramme und Achsen festgelegt werden können.
from aspose.cells import Workbook | |
from aspose.cells.charts import ChartType | |
from aspose.cells.drawing import GradientStyleType | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Adding a new worksheet to the Workbook object | |
sheetIndex = workbook.worksheets.add() | |
# Obtaining the reference of the newly added worksheet by passing its sheet index | |
worksheet = workbook.worksheets[sheetIndex] | |
# Adding sample values to cells | |
worksheet.cells.get("A1").put_value(50) | |
worksheet.cells.get("A2").put_value(100) | |
worksheet.cells.get("A3").put_value(150) | |
worksheet.cells.get("B1").put_value(60) | |
worksheet.cells.get("B2").put_value(32) | |
worksheet.cells.get("B3").put_value(50) | |
# Adding a chart to the worksheet | |
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
# Accessing the instance of the newly added chart | |
chart = worksheet.charts[chartIndex] | |
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
chart.n_series.add("A1:B3", True) | |
# Setting the foreground color of the plot area | |
chart.plot_area.area.foreground_color = Color.blue | |
# Setting the foreground color of the chart area | |
chart.chart_area.area.foreground_color = Color.yellow | |
# Setting the foreground color of the 1st SeriesCollection area | |
chart.n_series[0].area.foreground_color = Color.red | |
# Setting the foreground color of the area of the 1st SeriesCollection point | |
chart.n_series[0].points[0].area.foreground_color = Color.cyan | |
# Filling the area of the 2nd SeriesCollection with a gradient | |
chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1) | |
# Setting the title of a chart | |
chart.title.text = "Title" | |
# Setting the font color of the chart title to blue | |
chart.title.font.color = Color.blue | |
# Setting the title of category axis of the chart | |
chart.category_axis.title.text = "Category" | |
# Setting the title of value axis of the chart | |
chart.value_axis.title.text = "Value" | |
# Saving the Excel file | |
workbook.save(dataDir + "book1.out.xls") |