Sparkline
Sparklines ialah carta miniatur yang disematkan dalam sel individu, diperkenalkan dalam Excel 2010. aspose-cells-foss menguruskan sparklines melalui SparklineGroup dan SparklineGroupCollection (ws.sparkline_groups). Setiap kumpulan memegang satu atau lebih Sparkline objek yang berkongsi jenis dan tetapan warna yang sama.
ImageRenderOptions: aspose.cells_foss
from aspose.cells_foss import SparklineType, SparklineEmptyCells, Sparkline, SparklineGroupSparklineType
SparklineType adalah satu IntEnum yang mengenal pasti bentuk visual kumpulan sparkline.
| Name | Type | Access | Description |
|---|---|---|---|
data_range | `` | Read | Gets the data range. |
cell_reference | `` | Read | Gets the cell reference. |
SparklineEmptyCells
SparklineEmptyCells adalah satu IntEnum yang mengawal cara sel kosong ditangani dalam sparkline.
| Signature | Description |
|---|---|
__init__(data_range: str, cell_reference: str) | |
copy() | Creates and returns a duplicate of this Sparkline object |
ImageRenderOptions
Satu Sparkline mengikat satu julat data kepada satu lokasi sel.
ImageRenderOptions
Sparkline(data_range: str, cell_reference: str)ImageRenderOptions
SparklineGroup
A SparklineGroup menentukan tetapan visual yang dikongsi (jenis, warna, pengendalian sel kosong) untuk satu set sparkline. SparklineGroup objek tidak dibina secara langsung — gunakan ws.sparkline_groups.add(...) atau ws.sparkline_groups.add_group(...).
ImageRenderOptions
ImageRenderOptions
add_sparkline
group.add_sparkline(data_range: str, cell_reference: str) -> SparklineMenambah sparkline individu ke kumpulan ini dan mengembalikan yang baru Sparkline objek.
SparklineGroupCollection
SparklineGroupCollection diakses sebagai ws.sparkline_groups. Ia mengandungi semua kumpulan sparkline pada lembar kerja.
ImageRenderOptions
add
ws.sparkline_groups.add(
sparkline_type=SparklineType.LINE,
data_range=None,
is_vertical=False,
location_range=None
) -> SparklineGroupMencipta kumpulan baru dan secara pilihan mengisinya dengan sparkline yang dihasilkan daripada data_range (baris atau lajur bergantung pada is_vertical) diletakkan ke dalam sel yang diterangkan oleh location_range. Mengembalikan yang baru SparklineGroup.
add_group
ws.sparkline_groups.add_group(sparkline_type=SparklineType.LINE) -> SparklineGroupMencipta kumpulan kosong bagi jenis yang diberikan. Sparkline mesti ditambah secara individu dengan group.add_sparkline(...).
Sifat dan Iterasi
ImageRenderOptions
Contoh berikut menulis data pendapatan bulanan untuk tiga wilayah dan menambah sparkline garis untuk setiap baris.
from aspose.cells_foss import Workbook, SparklineType, SparklineEmptyCells
wb = Workbook()
ws = wb.worksheets[0]
ws.name = "Trends"
# Write headers
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
for col, m in enumerate(months):
ws.cells[0][col + 1].put_value(m)
ws.cells["A1"].put_value("Region")
ws.cells["H1"].put_value("Trend")
# Write three rows of data
regions = [
("North", [12000, 14500, 13800, 16200, 15900, 17400]),
("South", [9800, 10200, 11500, 10900, 12300, 13100]),
("West", [7500, 8100, 7900, 8800, 9200, 10500]),
]
for row_i, (name, values) in enumerate(regions, start=1):
ws.cells[row_i][0].put_value(name)
for col_i, v in enumerate(values):
ws.cells[row_i][col_i + 1].put_value(v)
# Add a line sparkline group — one sparkline per data row
group = ws.sparkline_groups.add(
sparkline_type=SparklineType.LINE,
data_range="Trends!B2:G4",
is_vertical=False,
location_range="Trends!H2:H4",
)
# Customize colors
group.color_series = "4472C4" # blue lines
group.color_high = "70AD47" # green for peak
group.color_low = "FF0000" # red for trough
group.display_empty_cells_as = SparklineEmptyCells.GAP
wb.save("sparklines.xlsx")