Grafiklerde Şekiller
Grafiğe Etiket Denetimi Ekleme
Etiketler, bir elektronik tablonun içeriği hakkında kullanıcılara bilgi verme aracı sağlar. Aspose.Cells for Python via .NET, grafiğe ve etiketlere eklemeye ve düzenlemeye imkan sağlar.
aspose.cells.drawing.ShapeCollection sınıfı, bir add_label_in_chart yöntemi adında bir yöntem sağlar. Bu yöntem, bir etiket denetimini grafiğe eklemek için kullanılır. Yöntem için kullanılan parametrelerin bir listesi aşağıda verilmiştir:
- üst – etiketin sol üst köşesinden dikey ofset (1/4000 biriminde grafik alanı).
- sol – etiketin sol üst köşesinden yatay ofset (1/4000 biriminde grafik alanı).
- yükseklik – etiketin yüksekliği, grafik alanının 1/4000 biriminde.
- genişlik – etiketin genişliği, grafik alanının 1/4000 biriminde.
Yöntem, aspose.cells.drawing.Label nesnesi döndürür. Label sınıfı, grafikteki bir etiketi temsil eder. Bazı önemli üyelere sahiptir:
- text (özellik) – bir etiketin başlık dizgisini belirtir.
- fill (özellik) – doldurma rengi özelliklerini belirtir.
Aşağıdaki örnek, bir etiketin grafiğe nasıl ekleneceğini göstermektedir. Örnek, içinde bir grafik bulunan bir tasarımcı dosyası (exp_piechart.xls) kullanır. Bu dosyayı, grafikte bir etiket eklemek için kullanırız. Aşağıda, grafiğe bir etiket eklemek için orijinal kod verilmiştir. Kodu yürüttüğünüzde aşağıdaki çıktı üretilir.
from aspose.cells import Workbook | |
from aspose.cells.drawing import PlacementType | |
# 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(".") | |
# Open the existing file. | |
workbook = Workbook(dataDir + "chart.xls") | |
# Get the designer chart in the second sheet. | |
sheet = workbook.worksheets[1] | |
chart = sheet.charts[0] | |
# Add a new label to the chart. | |
label = chart.shapes.add_label_in_chart(100, 100, 350, 900) | |
# Set the caption of the label. | |
label.text = "A Label In Chart" | |
# Set the Placement Type, the way the | |
# Label is attached to the cells. | |
label.placement = PlacementType.FREE_FLOATING | |
# Save the excel file. | |
workbook.save(dataDir + "chart.out.xls") |
Grafiğe TextBox Kontrolü Ekleme
Bir raporda önemli bilgileri vurgulamanın bir yolu, bir metin kutusu kullanmaktır. Örneğin, şirket adını vurgulamak veya en yüksek satış yapılan coğrafi bölgeyi belirtmek için metin girin. aspose.cells.drawing.ShapeCollection sınıfı, grafiğe bir metin kutusu denetimi eklemek için kullanılan add_text_box_in_chart adında bir yöntem sağlar. Aşağıdaki parametre listesi, yöntem için kullanılan parametreleri gösterir:
- top – metin kutusunun grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
- left – metin kutusunun grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
- height – metin kutusunun yüksekliği, grafik alanının 1/4000 biriminde.
- width – metin kutusunun genişliği, grafik alanının 1/4000 biriminde.
Yöntem, bir aspose.cells.drawing.TextBox nesnesi döndürür. TextBox sınıfı, grafiğe bir metin kutusu temsil eder.
Aşağıdaki örnek, bir metin kutusunun grafiğe nasıl ekleneceğini gösterir. Örnek, içinde bir grafik bulunan önceki bir tasarımcı dosyası (exp_piechart.xls) kullanır. Bu dosyayı, grafiğe metin kutusu eklemek için kullanırız. Aşağıda, grafiğe metin kutusu eklemek için orijinal kod bulunmaktadır.
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle | |
from aspose.pydrawing import Color | |
# 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(".") | |
# Open the existing file. | |
workbook = Workbook(dataDir + "chart.xls") | |
# Get the designer chart in the second sheet. | |
sheet = workbook.worksheets[1] | |
chart = sheet.charts[0] | |
# Add a new textbox to the chart. | |
textbox0 = chart.shapes.add_text_box_in_chart(100, 1100, 350, 2550) | |
# Fill the text. | |
textbox0.text = "Sales By Region" | |
# Get the textbox text frame. | |
# Aspose.Cells.Drawing.MsoTextFrame textframe0 = textbox0.TextFrame; | |
# Set the textbox to adjust it according to its contents. | |
# textframe0.AutoSize = true; | |
# Set the font color. | |
textbox0.font.color = Color.maroon | |
# Set the font to bold. | |
textbox0.font.is_bold = True | |
# Set the font size. | |
textbox0.font.size = 14 | |
# Set font attribute to italic. | |
textbox0.font.is_italic = True | |
# Get the filformat of the textbox. | |
fillformat = textbox0.fill | |
# Get the lineformat type of the textbox. | |
lineformat = textbox0.line | |
# Set the line weight. | |
lineformat.weight = 2.0 | |
# Set the dash style to solid. | |
lineformat.dash_style = MsoLineDashStyle.SOLID | |
# Save the excel file. | |
workbook.save(dataDir + "chart.out.xls") |
Grafiğe Resim Ekleme
Aspose.Cells for Python via .NET, grafiğe resim eklemenize olanak tanır; örneğin, bir resim ekleyerek grafiği veya içeriğine vurgu yapabilir veya daha anlamlı hale getirebilirsiniz, veya marka resmi dosyası ekleyebilirsiniz.
aspose.cells.drawing.ShapeCollection sınıfı, grafiğe bir resim nesnesi eklemek için kullanılan add_picture_in_chart adında bir yöntem sağlar. Aşağıdaki parametre listesi, yöntem için kullanılan parametreleri gösterir:
- top – resmin, grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
- left – resmin, grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
- stream – resim verisini içeren bir akım nesnesi.
- widthScale – resmin genişlik ölçeği, yüzde değeri.
- heightScale – resmin yükseklik ölçeği, yüzde değeri.
Yöntem, bir aspose.cells.drawing.Picture nesnesi döndürür. Picture sınıfı, grafiğe bir resim nesnesi temsil eder.
Aşağıdaki örnek, bir resmin grafiğe nasıl ekleneceğini gösterir. Örnek, içinde bir grafik bulunan önceki bir tasarımcı dosyası (exp_piechart.xls) kullanır. Bu dosyayı, grafiğe bir resim eklemek için kullanırız. Aşağıda, grafiğe resim eklemek için orijinal kod bulunmaktadır.
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle | |
# 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(".") | |
# Open the existing file. | |
workbook = Workbook(dataDir + "chart.xls") | |
# Get an image file to the stream. | |
stream = open(dataDir + "logo.jpg", "rb") | |
# Get the designer chart in the second sheet. | |
sheet = workbook.worksheets[0] | |
chart = sheet.charts[0] | |
# Add a new picture to the chart. | |
pic0 = chart.shapes.add_picture_in_chart(50, 50, stream, 40, 40) | |
# Get the lineformat type of the picture. | |
lineformat = pic0.line | |
# Set the dash style. | |
lineformat.dash_style = MsoLineDashStyle.SOLID | |
# Set the line weight. | |
lineformat.weight = 4.0 | |
# Save the excel file. | |
workbook.save(dataDir + "chart.out.xls") |
Grafiğe Onay Kutusu Ekleme
Aspose.Cells for Python via .NET, MsoDrawingType sıralaması kullanarak bir grafik sayfasına onay kutuları eklemenize olanak sağlar. Aşağıdaki örnek, bir grafik sayfasına onay kutusu eklemeyi göstermektedir.
Aşağıdaki resim, çıktı dosyasındaki grafik tablosunu içeren onay kutusu göstermektedir.
Aşağıdaki kod parçası tarafından oluşturulan çıktı dosyası, referansınız için ekte bulunmaktadır.
from aspose.cells import SheetType, Workbook | |
from aspose.cells.charts import ChartType | |
from aspose.cells.drawing import MsoDrawingType, PlacementType | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Adding a chart to the worksheet | |
index = workbook.worksheets.add(SheetType.CHART) | |
sheet = workbook.worksheets[index] | |
sheet.charts.add_floating_chart(ChartType.COLUMN, 0, 0, 1024, 960) | |
sheet.charts[0].n_series.add("{1,2,3}", False) | |
# Add checkbox to the chart. | |
sheet.charts[0].shapes.add_shape_in_chart(MsoDrawingType.CHECK_BOX, PlacementType.MOVE, 400, 400, 1000, 600) | |
sheet.charts[0].shapes[0].text = "CheckBox 1" | |
# Save the excel file. | |
workbook.save(outputDir + "InsertCheckboxInChartSheet_out.xlsx") |