範囲のボーダーを設定
Contents
[
Hide
]
可能な使用シナリオ
範囲の境界線を設定する場合、個々のセルを個別に設定する必要はありません。範囲で境界線を設定できます。Aspose.Cells for Python via .NETはこの機能を提供しています。 この記事では、Aspose.Cells for Python via .NETを使用して範囲の境界線を設定するサンプルコードを提供しています。
Excelでの範囲の境界線の設定方法
Excelで範囲のボーダーを設定するには、次の手順に従います:
- ボーダーを適用する範囲のセルを選択します。
- リボンの「ホーム」タブに移動し、「フォント」グループを検索します。
- 「フォント」グループ内で、「ボーダー」ドロップダウンボタンをクリックします。
- ドロップダウンメニュー内のオプションから適用するボーダーの種類を選択します。プリセットのボーダースタイルを選択するか、独自のボーダーをカスタマイズすることができます。
- 希望のボーダースタイルを選択したら、そのボーダーが選択したセル範囲に適用されます。
Aspose.Cells for Python Excelライブラリを使用した範囲の境界線の設定方法
この例では、次のことができます:
- ワークブックを作成する。
- 最初のワークシートのセルにデータを追加する。
- Rangeを作成します。
- 範囲の内側のボーダーを設定します。
- 範囲の外側のボーダーを設定します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import BorderType, CellBorderType, Workbook | |
from aspose.pydrawing import Color | |
# Instantiating an Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the newly added worksheet | |
ws = workbook.worksheets[0] | |
cells = ws.cells | |
# Setting the value to the cells | |
cell = cells.get("A1") | |
cell.put_value("Fruit") | |
cell = cells.get("B1") | |
cell.put_value("Count") | |
cell = cells.get("C1") | |
cell.put_value("Price") | |
cell = cells.get("A2") | |
cell.put_value("Apple") | |
cell = cells.get("A3") | |
cell.put_value("Mango") | |
cell = cells.get("A4") | |
cell.put_value("Blackberry") | |
cell = cells.get("A5") | |
cell.put_value("Cherry") | |
cell = cells.get("B2") | |
cell.put_value(5) | |
cell = cells.get("B3") | |
cell.put_value(3) | |
cell = cells.get("B4") | |
cell.put_value(6) | |
cell = cells.get("B5") | |
cell.put_value(4) | |
cell = cells.get("C2") | |
cell.put_value(5) | |
cell = cells.get("C3") | |
cell.put_value(20) | |
cell = cells.get("C4") | |
cell.put_value(30) | |
cell = cells.get("C5") | |
cell.put_value(60) | |
# Create a range (A1:C5). | |
range = cells.create_range("A1", "C5") | |
# set inner borer of range | |
innerColor = workbook.create_cells_color() | |
innerColor.color = Color.red | |
range.set_inside_borders(BorderType.VERTICAL, CellBorderType.THIN, innerColor) | |
innerColor.color = Color.green | |
range.set_inside_borders(BorderType.HORIZONTAL, CellBorderType.THIN, innerColor) | |
# set outer borer of range | |
outerColor = workbook.create_cells_color() | |
outerColor.color = Color.blue | |
range.set_outline_borders(CellBorderType.THIN, outerColor) | |
workbook.save("out.xlsx") |