コントロールの管理

Contents
[ ]

紹介

開発者は、テキストボックス、チェックボックス、ラジオボタン、コンボボックス、ラベル、ボタン、線、長方形、弧、楕円、スピナー、スクロールバー、グループボックスなどのさまざまな描画オブジェクトを追加できます。Aspose.Cells for Python via .NET は、すべての描画オブジェクトを含む Aspose.Cells.Drawing 名前空間を提供します。ただし、一部の描画オブジェクトや図形はまだサポートされていません。Microsoft Excel を使用してこれらの描画オブジェクトをデザイナーのスプレッドシートで作成し、その後、そのデザイナーのスプレッドシートを Aspose.Cells にインポートしてください。Aspose.Cells for Python via .NET は、これらの描画オブジェクトをデザイナーのスプレッドシートからロードし、生成されたファイルに書き込むことを可能にします。

ワークシートにテキストボックスコントロールを追加

レポート内の重要な情報を強調する一つの方法は、テキストボックスを使用することです。例えば、会社名をハイライトするためや、売上高が最も高い地域を示すためなどです。Aspose.Cells for Python via .NET は、コレクションに新しいテキストボックスを追加するために TextBoxCollection クラスを提供します。もう一つのクラス TextBox は、すべての設定タイプを定義するためのテキストボックスを表します。重要なメンバーがいくつかあります:

  • text_frameプロパティは、テキストボックスの内容を調整するために使用されるMsoTextFrameオブジェクトを返します。
  • placementプロパティは配置タイプを指定します。
  • fontプロパティはフォント属性を指定します。
  • add_hyperlinkメソッドは、テキストボックスにハイパーリンクを追加します。
  • fill_formatプロパティは、テキストボックスの塗りつぶし形式を設定するために使用されるMsoFillFormatオブジェクトを返します。
  • line_formatプロパティは、テキストボックスのラインのスタイルと太さを通常設定するために使用されるMsoLineFormatオブジェクトを返します。
  • textプロパティは、テキストボックスの入力テキストを指定します。

次の例では、ブックの最初のワークシートに2つのテキストボックスを作成します。最初のテキストボックスはさまざまなフォーマット設定で整備されています。2番目はシンプルなものです。

from aspose.cells import Workbook
from aspose.cells.drawing import MsoLineDashStyle, PlacementType
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)
# Instantiate a new Workbook.
workbook = Workbook()
# Get the first worksheet in the book.
worksheet = workbook.worksheets[0]
# Add a new textbox to the collection.
textboxIndex = worksheet.text_boxes.add(2, 1, 160, 200)
# Get the textbox object.
textbox0 = worksheet.text_boxes[textboxIndex]
# Fill the text.
textbox0.text = "ASPOSE______The .NET & JAVA Component Publisher!"
# Get the textbox text frame.
# MsoTextFrame textframe0 = textbox0.TextFrame;
# Set the textbox to adjust it according to its contents.
# textframe0.AutoSize = true;
# Set the placement.
textbox0.placement = PlacementType.FREE_FLOATING
# Set the font color.
textbox0.font.color = Color.blue
# 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
# Add a hyperlink to the textbox.
textbox0.add_hyperlink("http:// Www.aspose.com/")
# 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 = 6.0
# Set the dash style to squaredot.
lineformat.dash_style = MsoLineDashStyle.SQUARE_DOT
# Add another textbox.
textboxIndex = worksheet.text_boxes.add(15, 4, 85, 120)
# Get the second textbox.
textbox1 = worksheet.text_boxes[textboxIndex]
# Input some text to it.
textbox1.text = "This is another simple text box"
# Set the placement type as the textbox will move and
# Resize with cells.
textbox1.placement = PlacementType.MOVE_AND_SIZE
# Save the excel file.
workbook.save(dataDir + "book1.out.xls")

デザイナースプレッドシート内のテキストボックスコントロールの操作

Aspose.Cells for Python via .NET は、デザイナーのワークシート内のテキストボックスにアクセスし、それらを操作することも可能です。Worksheet.TextBoxes プロパティを使用して、シート内のテキストボックスのコレクションを取得します。

次の例では、上記の例で作成したMicrosoft Excelファイルを使用しています。2つのテキストボックスのテキストを取得し、2番目のテキストボックスのテキストを変更してファイルを保存します。

from aspose.cells import Workbook
# 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(".")
# Instantiate a new Workbook.
# Open the existing excel file.
workbook = Workbook(dataDir + "book1.xls")
# Get the first worksheet in the book.
worksheet = workbook.worksheets[0]
# Get the first textbox object.
textbox0 = worksheet.text_boxes[0]
# Obtain the text in the first textbox.
text0 = textbox0.text
# Get the second textbox object.
textbox1 = worksheet.text_boxes[1]
# Obtain the text in the second textbox.
text1 = textbox1.text
# Change the text of the second textbox.
textbox1.text = "This is an alternative text"
# Save the excel file.
workbook.save(dataDir + "output.out.xls")

ワークシートにチェックボックスコントロールを追加する

チェックボックスは、true または false、はい または いいえなどの二つの選択肢の中からユーザーに選ばせる方法を提供したい場合に便利です。Aspose.Cells for Python via .NET では、ワークシート内にチェックボックスを使用できます。例えば、特定の買収について考慮するかどうかを示す財務予測ワークシートを作成した場合、ワークシートの上部にチェックボックスを配置したいことがあります。その後、そのチェックボックスの状態を別のセルにリンクさせ、チェックボックスが選択されている場合はセルの値が True に、選択されていない場合は False になるように設定できます。

Microsoft Excel の使用

ワークシートにチェックボックスコントロールを配置するには、次の手順に従います。

  1. フォームツールバーが表示されていることを確認します。
  2. フォームツールバーのチェックボックスツールをクリックします。
  3. ワークシートエリアで、チェックボックスとチェックボックスの横に表示されるラベルを定義するためにクリックしてドラッグします。
  4. チェックボックスが配置されたら、マウスカーソルをラベル領域に移動してラベルを変更します。
  5. セルリンクフィールドで、このチェックボックスをリンクするセルのアドレスを指定します。
  6. OK をクリックします。

Aspose.Cells for Python via .NETを使用して

Aspose.Cells for Python via .NET は、新しいチェックボックスをコレクションに追加するために CheckBoxCollection クラスを提供します。もう一つのクラス Aspose.Cells.Drawing.CheckBox はチェックボックスを表します。重要なメンバーがいくつかあります:

  • linked_cellプロパティは、チェックボックスにリンクされるセルを指定します。
  • textプロパティは、チェックボックスに関連付けられたテキスト文字列を指定します。これはチェックボックスのラベルです。
  • valueプロパティは、チェックボックスが選択されているかどうかを指定します。

次の例では、ワークシートにチェックボックスを追加する方法を示しています。

from aspose.cells import Workbook
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Add a checkbox to the first worksheet in the workbook.
index = excelbook.worksheets[0].check_boxes.add(5, 5, 100, 120)
# Get the checkbox object.
checkbox = excelbook.worksheets[0].check_boxes[index]
# Set its text string.
checkbox.text = "Click it!"
# Put a value into B1 cell.
excelbook.worksheets[0].cells.get("B1").put_value("LnkCell")
# Set B1 cell as a linked cell for the checkbox.
checkbox.linked_cell = "B1"
# Check the checkbox by default.
checkbox.value = True
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

ワークシートにラジオボタンコントロールを追加する

ラジオボタン、またはオプションボタンは、円形のボックスからなるコントロールです。ユーザーはラウンドボックスを選択することで決定を行います。ラジオボタンは通常、他のラジオボタンに伴って表示され、グループとして振る舞います。ユーザーは1つのボタンのみを選択することで、どのボタンが有効か決定します。ユーザーが1つのボタンをクリックすると、それは選択されます。グループ内の1つのボタンが選択されると、同じグループのボタンは空になります。

Microsoft Excel の使用

ワークシートにラジオボタンコントロールを配置するには、次の手順に従います。

  1. フォーム ツールバーが表示されていることを確認します。
  2. オプションボタンツールをクリックします。
  3. ワークシートで、オプションボタンとオプションボタンの横に表示されるラベルを定義するためにクリックしてドラッグします。
  4. ワークシートにラジオボタンを配置したら、マウスカーソルをラベル領域に移動してラベルを変更します。
  5. セルリンクフィールドで、このラジオボタンがリンクされるセルのアドレスを指定します。
  6. OK をクリックします。

Aspose.Cells for Python via .NETを使用して

Aspose.Cells.Drawing.ShapeCollectionクラスには、ワークシートにラジオボタンコントロールを追加するために使用されるadd_radio_buttonというメソッドがあります。このメソッドはAspose.Cells.Drawing.RadioButtonオブジェクトを返します。また、Aspose.Cells.Drawing.RadioButtonクラスもあります。

  • linked_cellプロパティは、ラジオボタンにリンクされるセルを指定します。
  • textプロパティは、ラジオボタンに関連付けられたテキスト文字列を指定します。これはラジオボタンのラベルです。
  • is_checkedプロパティは、ラジオボタンが選択されているかどうかを指定します。
  • fill_formatプロパティは、ラジオボタンの塗りつぶし形式を指定します。
  • line_formatプロパティは、オプションボタンの線の形式スタイルを指定します。

次の例では、ワークシートにラジオボタンを追加する方法を示しています。例では、3つの年齢グループを表すラジオボタンが追加されています。

from aspose.cells import Workbook
from aspose.cells.drawing import MsoLineDashStyle
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Insert a value.
excelbook.worksheets[0].cells.get("C2").put_value("Age Groups")
# Set the font text bold.
excelbook.worksheets[0].cells.get("C2").get_style().font.is_bold = True
# Add a radio button to the first sheet.
radio1 = excelbook.worksheets[0].shapes.add_radio_button(3, 0, 2, 0, 30, 110)
# Set its text string.
radio1.text = "20-29"
# Set A1 cell as a linked cell for the radio button.
radio1.linked_cell = "A1"
# Make the radio button 3-D.
radio1.shadow = True
# Set the weight of the radio button.
radio1.line.weight = 4.0
# Set the dash style of the radio button.
radio1.line.dash_style = MsoLineDashStyle.SOLID
# Add another radio button to the first sheet.
radio2 = excelbook.worksheets[0].shapes.add_radio_button(6, 0, 2, 0, 30, 110)
# Set its text string.
radio2.text = "30-39"
# Set A1 cell as a linked cell for the radio button.
radio2.linked_cell = "A1"
# Make the radio button 3-D.
radio2.shadow = True
# Set the weight of the radio button.
radio2.line.weight = 4.0
# Set the dash style of the radio button.
radio2.line.dash_style = MsoLineDashStyle.SOLID
# Add another radio button to the first sheet.
radio3 = excelbook.worksheets[0].shapes.add_radio_button(9, 0, 2, 0, 30, 110)
# Set its text string.
radio3.text = "40-49"
# Set A1 cell as a linked cell for the radio button.
radio3.linked_cell = "A1"
# Make the radio button 3-D.
radio3.shadow = True
# Set the weight of the radio button.
radio3.line.weight = 4.0
# Set the dash style of the radio button.
radio3.line.dash_style = MsoLineDashStyle.SOLID
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

ワークシートにコンボボックスコントロールを追加する

データの入力を容易にするか、定義した項目にエントリを制限するためには、ワークシートの他のセルからコンパイルされる有効なエントリのコンボボックス、またはドロップダウンリストを作成できます。セルのドロップダウンリストを作成すると、そのセルの隣に矢印が表示されます。そのセルに情報を入力するには、矢印をクリックし、その後、欲しいエントリをクリックします。

Microsoft Excel の使用

ワークシートにコンボボックスコントロールを配置するには、次の手順に従います:

  1. フォーム ツールバーが表示されていることを確認します。
  2. コンボボックス ツールをクリックします。
  3. ワークシートエリアで、コンボボックスを保持する四角形を定義するためにクリックしてドラッグします。
  4. コンボボックスがワークシートに配置されたら、コントロールを右クリックして コントロールの書式設定 をクリックし、入力範囲を指定します。
  5. セルリンク フィールドで、このコンボボックスをリンクするセルのアドレスを指定します。
  6. OK をクリックします。

Aspose.Cells for Python via .NETを使用して

クラス Aspose.Cells.Drawing.ShapeCollectionadd_combo_box という名前のメソッドを提供し、これはワークシートにコンボボックスコントロールを追加するために使用されます。このメソッドは Aspose.Cells.Drawing.ComboBox オブジェクトを返します。Aspose.Cells.Drawing.ComboBox クラスはコンボボックスを表します。いくつかの重要なメンバを持っています:

  • linked_cell プロパティはコンボボックスにリンクされたセルを指定します。
  • input_range プロパティはコンボボックスを埋めるために使用されるワークシートのセル範囲を指定します。
  • drop_down_lines プロパティはドロップダウン部分に表示されるリスト行の数を指定します。
  • shadow プロパティはコンボボックスが 3D シェーディングを持っているかどうかを示します。

次の例は、ワークシートにコンボボックスを追加する方法を示しています。

from aspose.cells import Workbook
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)
# Create a new Workbook.
workbook = Workbook()
# Get the first worksheet.
sheet = workbook.worksheets[0]
# Get the worksheet cells collection.
cells = sheet.cells
# Input a value.
cells.get("B3").put_value("Employee:")
# Set it bold.
cells.get("B3").get_style().font.is_bold = True
# Input some values that denote the input range
# For the combo box.
cells.get("A2").put_value("Emp001")
cells.get("A3").put_value("Emp002")
cells.get("A4").put_value("Emp003")
cells.get("A5").put_value("Emp004")
cells.get("A6").put_value("Emp005")
cells.get("A7").put_value("Emp006")
# Add a new combo box.
comboBox = sheet.shapes.add_combo_box(2, 0, 2, 0, 22, 100)

ワークシートにラベルコントロールを追加する

ラベルは、スプレッドシートの内容についてユーザーに情報を提供する手段です。Aspose.Cells for Python via .NET では、ワークシート内のラベルを追加・操作することが可能です。ShapeCollection クラスは、add_label というメソッド提供し、これを使用してラベルコントロールをワークシートに追加します。このメソッドは Label オブジェクトを返します。Label クラスは、ワークシート内のラベルを表します。重要なメンバーがいくつかあります。

  • text メソッドはラベルのキャプション文字列を指定します。
  • placement メソッドは、ラベルがワークシート内のセルにどのようにアタッチされるかを指定します。

次の例は、ワークシートにラベルを追加する方法を示しています。

from aspose.cells import Workbook
from aspose.cells.drawing import PlacementType
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)
# Create a new Workbook.
workbook = Workbook()
# Get the first worksheet in the workbook.
sheet = workbook.worksheets[0]
# Add a new label to the worksheet.
label = sheet.shapes.add_label(2, 0, 2, 0, 60, 120)
# Set the caption of the label.
label.text = "This is a Label"
# Set the Placement Type, the way the
# Label is attached to the cells.
label.placement = PlacementType.FREE_FLOATING
# Saves the file.
workbook.save(dataDir + "book1.out.xls")

ワークシートにリストボックスコントロールを追加する

リストボックスコントロールは、単一または複数のアイテム選択を可能にするリストコントロールを作成します。

Microsoft Excel の使用

ワークシートにリストボックスコントロールを配置するには:

  1. フォーム ツールバーが表示されていることを確認します。
  2. リストボックス ツールをクリックします。
  3. ワークシートエリアで、リストボックスを保持する四角形を定義するためにクリックしてドラッグします。
  4. リストボックスがワークシートに配置されたら、コントロールを右クリックして コントロールの書式設定 をクリックし、入力範囲を指定します。
  5. セルリンク フィールドで、このリストボックスをリンクするセルのアドレスを指定し、選択タイプ(単一、複数、拡張)属性を設定します。
  6. OK をクリックします。

Aspose.Cells for Python via .NETを使用して

クラス ShapeCollection は、ワークシートにリストボックスコントロールを追加するために使用される add_list_box という名前のメソッドを提供します。このメソッドは Aspose.Cells.Drawing.ListBox オブジェクトを返します。ListBox クラスはリストボックスを表します。いくつかの重要なメンバを持っています:

  • linked_cell メソッドはリストボックスにリンクされたセルを指定します。
  • input_range メソッドはリストボックスを埋めるために使用されるワークシートのセル範囲を指定します。
  • selection_type メソッドはリストボックスの選択モードを指定します。
  • shadow メソッドはリストボックスに3Dシェーディングがあるかどうかを示します。

次の例は、ワークシートにリストボックスを追加する方法を示しています。

from aspose.cells import Workbook
from aspose.cells.drawing import PlacementType, SelectionType
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)
# Create a new Workbook.
workbook = Workbook()
# Get the first worksheet.
sheet = workbook.worksheets[0]
# Get the worksheet cells collection.
cells = sheet.cells
# Input a value.
cells.get("B3").put_value("Choose Dept:")
# Set it bold.
cells.get("B3").get_style().font.is_bold = True
# Input some values that denote the input range
# For the list box.
cells.get("A2").put_value("Sales")
cells.get("A3").put_value("Finance")
cells.get("A4").put_value("MIS")
cells.get("A5").put_value("R&D")
cells.get("A6").put_value("Marketing")
cells.get("A7").put_value("HRA")
# Add a new list box.
listBox = sheet.shapes.add_list_box(2, 0, 3, 0, 122, 100)
# Set the placement type.
listBox.placement = PlacementType.FREE_FLOATING
# Set the linked cell.
listBox.linked_cell = "A1"
# Set the input range.
listBox.input_range = "A2:A7"
# Set the selection tyle.
listBox.selection_type = SelectionType.SINGLE
# Set the list box with 3-D shading.
listBox.shadow = True
# Saves the file.
workbook.save(dataDir + "book1.out.xls")

ボタンコントロールをワークシートに追加する

ボタンは何かアクションを行うために便利です。時には、ボタンにVBAマクロを割り当てたり、Webページを開くためのハイパーリンクを割り当てることも有用です。

Microsoft Excel の使用

ボタンコントロールをワークシートに配置するには:

  1. フォーム ツールバーが表示されていることを確認します。
  2. ボタン ツールをクリックします。
  3. ワークシート領域でクリックしてドラッグして、ボタンを配置する矩形を定義します。
  4. リストボックスがワークシートに配置されたら、コントロールを右クリックして フォーマットコントロール を選択し、VBAマクロを指定し、フォント、配置、サイズ、余白などに関連する属性を設定します。
  5. OK をクリックします。

Aspose.Cells for Python via .NETを使用して

ShapeCollection クラスは、ボタンコントロールをワークシートに追加するための add_button という名前のメソッドを提供します。このメソッドは Aspose.Cells.Drawing.Button オブジェクトを返します。クラス Aspose.Cells.Drawing.Button はボタンを表します。いくつかの重要なメンバーがあります:

  • text プロパティはボタンのキャプションを指定します。
  • font プロパティはボタンコントロールのラベルのフォント属性を指定します。
  • placement プロパティはボタンがワークシートのセルにアタッチされる方法を指定します。
  • add_hyperlink プロパティはボタンコントロールにハイパーリンクを追加します。ボタンをクリックすると関連するURLに移動します。

次の例は、ワークシートにボタンを追加する方法を示しています。

from aspose.cells import Workbook
from aspose.cells.drawing import PlacementType
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)
# Create a new Workbook.
workbook = Workbook()
# Get the first worksheet in the workbook.
sheet = workbook.worksheets[0]
# Add a new button to the worksheet.
button = sheet.shapes.add_button(2, 0, 2, 0, 28, 80)
# Set the caption of the button.
button.text = "Aspose"
# Set the Placement Type, the way the
# Button is attached to the cells.
button.placement = PlacementType.FREE_FLOATING
# Set the font name.
button.font.name = "Tahoma"
# Set the caption string bold.
button.font.is_bold = True
# Set the color to blue.
button.font.color = Color.blue
# Set the hyperlink for the button.
button.add_hyperlink("http:// Www.aspose.com/")
# Saves the file.
workbook.save(dataDir + "book1.out.xls")

ワークシートにラインコントロールを追加する

Microsoft Excel の使用

  1. 描画 ツールバーで オートシェイプ をクリックし、ライン を指して、希望のラインスタイルを選択します。
  2. ドラッグしてラインを描きます。
  3. 次のいずれかを行います。
    1. ラインを開始点から15度の角度で制限するには、ドラッグしながら SHIFT キーを押します。
    2. 最初の端点から異なる方向にラインを長くするには、ドラッグしながら CTRL キーを押します。

Aspose.Cells for Python via .NETを使用して

ShapeCollection クラスは、ワークシートにラインシェイプを追加するために使用される add_line という名前のメソッドを提供します。このメソッドは LineShape オブジェクトを返します。クラス LineShape はラインを表します。いくつかの重要なメンバーがあります:

  • line_format メソッドはラインのフォーマットを指定します。
  • placement メソッドはラインがワークシートのセルにアタッチされる方法を指定します。

次の例は、ワークシートにラインを追加する方法を示しています。異なるスタイルで3つのラインが作成されます。

from aspose.cells import Workbook
from aspose.cells.drawing import MsoLineDashStyle, PlacementType
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)
# Instantiate a new Workbook.
workbook = Workbook()
# Get the first worksheet in the book.
worksheet = workbook.worksheets[0]
# Add a new line to the worksheet.
line1 = worksheet.shapes.add_line(5, 0, 1, 0, 0, 250)
# Set the line dash style
line1.line.dash_style = MsoLineDashStyle.SOLID
# Set the placement.
line1.placement = PlacementType.FREE_FLOATING
# Add another line to the worksheet.
line2 = worksheet.shapes.add_line(7, 0, 1, 0, 85, 250)
# Set the line dash style.
line2.line.dash_style = MsoLineDashStyle.DASH_LONG_DASH
# Set the weight of the line.
line2.line.weight = 4.0
# Set the placement.
line2.placement = PlacementType.FREE_FLOATING
# Add the third line to the worksheet.
line3 = worksheet.shapes.add_line(13, 0, 1, 0, 0, 250)
# Set the line dash style
line3.line.dash_style = MsoLineDashStyle.SOLID
# Set the placement.
line3.placement = PlacementType.FREE_FLOATING
# Make the gridlines invisible in the first worksheet.
workbook.worksheets[0].is_gridlines_visible = False
# Save the excel file.
workbook.save(dataDir + "book1.out.xls")

ラインに矢印を追加する

Aspose.Cells for Python via .NET は、矢印線を描画することも可能です。線に矢じりを追加したり、線の書式を設定したりすることができます。例えば、線の色を変更したり、線の太さやスタイルを指定したりできます。

次の例は、ラインに矢印を追加する方法を示しています。

from aspose.cells import Workbook
from aspose.cells.drawing import FillType, MsoArrowheadLength, MsoArrowheadStyle, MsoArrowheadWidth, PlacementType
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)
# Instantiate a new Workbook.
workbook = Workbook()
# Get the first worksheet in the book.
worksheet = workbook.worksheets[0]
# Add a line to the worksheet
line2 = worksheet.shapes.add_line(7, 0, 1, 0, 85, 250)
# Set the line color
line2.line.fill_type = FillType.SOLID
line2.line.solid_fill.color = Color.blue
# Set the weight of the line.
line2.line.weight = 3.0
# Set the placement.
line2.placement = PlacementType.FREE_FLOATING
# Set the line arrows.
line2.line.end_arrowhead_width = MsoArrowheadWidth.MEDIUM
line2.line.end_arrowhead_style = MsoArrowheadStyle.ARROW
line2.line.end_arrowhead_length = MsoArrowheadLength.MEDIUM
line2.line.begin_arrowhead_style = MsoArrowheadStyle.ARROW_DIAMOND
line2.line.begin_arrowhead_length = MsoArrowheadLength.MEDIUM
# Make the gridlines invisible in the first worksheet.
workbook.worksheets[0].is_gridlines_visible = False
# Save the excel file.
workbook.save(dataDir + "book1.out.xlsx")

ワークシートに長方形コントロールを追加する

Aspose.Cells for Python via .NET は、ワークシートに長方形の図形を描画することを可能にします。長方形、正方形などを作成でき、塗りつぶし色や境界線の色のフォーマットも可能です。例えば、長方形の色を変更したり、シェーディング色を設定したり、必要に応じて太さやスタイルを指定できます。

Microsoft Excel の使用

  1. 描画ツールバーで、長方形をクリックします。
  2. 長方形を描画するには、ドラッグします。
  3. 次のいずれかを行います。
    1. 長方形を開始点から正方形に描画するには、ドラッグしながらSHIFTキーを押し続けます。
    2. 長方形を中心点から描画するには、ドラッグしながらCTRLキーを押し続けます。

Aspose.Cells for Python via .NETを使用して

クラスShapeCollectionには、ワークシートに長方形を追加するためのadd_rectangleという名前のメソッドがあります。このメソッドはAspose.Cells.Drawing.RectangleShapeオブジェクトを返します。クラスAspose.Cells.Drawing.RectangleShapeは長方形を表します。いくつか重要なメンバーがあります。

  • line_formatプロパティは長方形の線の書式属性を指定します。
  • placementプロパティはPlacementTypeを指定し、長方形がワークシートのセルにアタッチされる方法を示します。
  • fill_formatプロパティは長方形の塗りつぶしの書式スタイルを指定します。

次の例は、ワークシートに長方形を追加する方法を示しています。

from aspose.cells import Workbook
from aspose.cells.drawing import MsoLineDashStyle, PlacementType
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Add a rectangle control.
rectangle = excelbook.worksheets[0].shapes.add_rectangle(3, 0, 2, 0, 70, 130)
# Set the placement of the rectangle.
rectangle.placement = PlacementType.FREE_FLOATING
# Set the line weight.
rectangle.line.weight = 4.0
# Set the dash style of the rectangle.
rectangle.line.dash_style = MsoLineDashStyle.SOLID
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

ワークシートに円弧コントロールを追加する

Aspose.Cells for Python via .NET は、楕円の図形を描画することもできます。シンプルな楕円や塗りつぶし楕円を作成し、塗りつぶし色や境界線の色をフォーマットすることができます。

Microsoft Excel の使用

  1. 図形の自動スタイルで、円弧をクリックします。
  2. 円弧を描画するには、ドラッグします。

Aspose.Cells for Python via .NETを使用して

クラスShapeCollectionには、ワークシートに円弧形状を追加するためのadd_arcという名前のメソッドがあります。このメソッドはAspose.Cells.Drawing.ArcShapeオブジェクトを返します。クラスAspose.Cells.Drawing.ArcShapeは円弧を表します。いくつか重要なメンバーがあります。

  • line_formatプロパティは円弧形状の線の書式属性を指定します。
  • placementプロパティはPlacementTypeを指定し、円弧がワークシートのセルにアタッチされる方法を示します。
  • fill_formatプロパティは形状の塗りつぶし形式スタイルを指定します。
  • lower_right_rowプロパティは右下の行インデックスを指定します。
  • lower_right_columnプロパティは右下の列インデックスを指定します。

次の例は、ワークシートに円弧形状を追加する方法を示しています。この例では、塗りつぶしの円弧形状とシンプルな円弧形状の2つを作成します。

from aspose.cells import Workbook
from aspose.cells.drawing import FillType, MsoLineDashStyle, PlacementType
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Add an arc shape.
arc1 = excelbook.worksheets[0].shapes.add_arc(2, 0, 2, 0, 130, 130)
# Set the fill shape color
arc1.fill.fill_type = FillType.SOLID
arc1.fill.solid_fill.color = Color.blue
# Set the placement of the arc.
arc1.placement = PlacementType.FREE_FLOATING
# Set the line weight.
arc1.line.weight = 1.0
# Set the dash style of the arc.
arc1.line.dash_style = MsoLineDashStyle.SOLID
# Add another arc shape.
arc2 = excelbook.worksheets[0].shapes.add_arc(9, 0, 2, 0, 130, 130)
# Set the line color
arc2.line.fill_type = FillType.SOLID
arc2.line.solid_fill.color = Color.blue
# Set the placement of the arc.
arc2.placement = PlacementType.FREE_FLOATING
# Set the line weight.
arc2.line.weight = 1.0
# Set the dash style of the arc.
arc2.line.dash_style = MsoLineDashStyle.SOLID
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

ワークシートに楕円コントロールを追加する

Aspose.Cells for Python via .NET は、ワークシートに楕円形を描くことも可能です。シンプルまたは塗りつぶしの楕円を作成し、塗りつぶし色や境界線の色を設定できます。

Microsoft Excel の使用

  • 図形ツールバーで、楕円をクリックします。
  • 楕円を描画するには、ドラッグします。
  • 以下のいずれか、または両方を行います。
  • 楕円を開始点から円として描画するには、ドラッグしながらSHIFTキーを押し続けます。
  • 楕円を中心点から描画するには、ドラッグしながらCTRLキーを押し続けます。

Aspose.Cells for Python via .NETを使用して

クラスShapeCollectionは、ワークシートに楕円形を追加するために使用されるadd_ovalというメソッドを提供します。このメソッドはAspose.Cells.Drawing.Ovalオブジェクトを返します。クラスAspose.Cells.Drawing.Ovalは楕円形を表し、いくつかの重要なメンバーがあります。

  • line_formatプロパティは楕円形の線形式属性を指定します。
  • placementプロパティはワークシート内のセルに楕円形を接続する方法を指定します。
  • fill_formatプロパティは形状の塗りつぶし形式スタイルを指定します。
  • lower_right_rowプロパティは右下の行インデックスを指定します。
  • lower_right_columnプロパティは右下の列インデックスを指定します。

次の例は、ワークシートに楕円形を追加する方法を示しています。この例では、塗りつぶしの楕円形と単純な円形の2つの楕円形を作成します。

from aspose.cells import Workbook
from aspose.cells.drawing import MsoLineDashStyle, PlacementType
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Add an oval shape.
oval1 = excelbook.worksheets[0].shapes.add_oval(2, 0, 2, 0, 130, 160)
# Set the placement of the oval.
oval1.placement = PlacementType.FREE_FLOATING
# Set the line weight.
oval1.line.weight = 1.0
# Set the dash style of the oval.
oval1.line.dash_style = MsoLineDashStyle.SOLID
# Add another oval (circle) shape.
oval2 = excelbook.worksheets[0].shapes.add_oval(9, 0, 2, 15, 130, 130)
# Set the placement of the oval.
oval2.placement = PlacementType.FREE_FLOATING
# Set the line weight.
oval2.line.weight = 1.0
# Set the dash style of the oval.
oval2.line.dash_style = MsoLineDashStyle.SOLID
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

ワークシートにスピンボックスコントロールを追加

スピンボックスは、上矢印と下矢印のついたボタン(スピンボタン)に付属したテキストボックスです。クリックすることで値を段階的に増減させることができます。スピンボックスを使用すると、財務モデルに入力された値の変化が、モデルの出力にどのように影響するかを見ることができます。特定の入力セルにスピンボタンを結びつけることが可能です。スピンボタンの上矢印または下矢印をクリックすると、対象の入力セルの整数値が増加または減少します。Aspose.Cells for Python via .NET では、ワークシートにスピナーを作成できます。

Microsoft Excel の使用

ワークシートにスピンボックスコントロールを配置するには:

  • フォームツールバーが表示されていることを確認します。
  • スピンボックスツールをクリックします。
  • ワークシート領域で、スピンボックスを保持する矩形を定義するためにクリックしてドラッグします。
  • スピンボックスをワークシートに配置したら、コントロールを右クリックして フォーマットコントロール をクリックし、最大値、最小値、増分値を指定します。
  • セルリンク フィールドに、このスピンボックスをリンクするセルのアドレスを指定します。
  • OK をクリックします。

Aspose.Cells for Python via .NETを使用して

クラスShapeCollectionは、ワークシートにスピンボックスコントロールを追加するために使用されるadd_spinnerというメソッドを提供します。このメソッドはAspose.Cells.Drawing.Spinnerオブジェクトを返します。クラスAspose.Cells.Drawing.Spinnerはスピンボックスを表し、いくつかの重要なメンバーがあります。

  • linked_cellプロパティは、スピンボックスにリンクされたセルを指定します。
  • maxプロパティは、スピンボックス範囲の最大値を指定します。
  • minプロパティは、スピンボックス範囲の最小値を指定します。
  • incremental_changeプロパティは、スピンボックスが1行スクロールされる値の量を指定します。
  • shadowプロパティは、スピンボックスに3Dシェーディングがあるかどうかを示します。
  • current_valueプロパティは、スピンボックスの現在の値を指定します。

次の例は、ワークシートにスピンボックスを追加する方法を示しています。

from aspose.cells import BackgroundType, Workbook
from aspose.cells.drawing import PlacementType
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Get the first worksheet.
worksheet = excelbook.worksheets[0]
# Get the worksheet cells.
cells = worksheet.cells
# Input a string value into A1 cell.
cells.get("A1").put_value("Select Value:")
# Set the font color of the cell.
cells.get("A1").get_style().font.color = Color.red
# Set the font text bold.
cells.get("A1").get_style().font.is_bold = True
# Input value into A2 cell.
cells.get("A2").put_value(0)
# Set the shading color to black with solid background.
cells.get("A2").get_style().foreground_color = Color.black
cells.get("A2").get_style().pattern = BackgroundType.SOLID
# Set the font color of the cell.
cells.get("A2").get_style().font.color = Color.white
# Set the font text bold.
cells.get("A2").get_style().font.is_bold = True
# Add a spinner control.
spinner = excelbook.worksheets[0].shapes.add_spinner(1, 0, 1, 0, 20, 18)
# Set the placement type of the spinner.
spinner.placement = PlacementType.FREE_FLOATING
# Set the linked cell for the control.
spinner.linked_cell = "A2"
# Set the maximum value.
spinner.max = 10
# Set the minimum value.
spinner.min = 0
# Set the incr. change for the control.
spinner.incremental_change = 2
# Set it 3-D shading.
spinner.shadow = True
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

ワークシートにスクロールバーコントロールを追加する

スクロールバーコントロールは、ワークシート上のデータを選択するのを支援するために使用され、スピンボックスコントロールと同様の方法でワークシートに追加できます。ワークシートにコントロールを追加し、セルにリンクすることで、コントロールの現在の位置の数値を返すことができます。

Microsoft Excel の使用

  • Excel 2003およびそれ以前のバージョンでは、フォームツールバーの スクロールバー ボタンをクリックし、高さでセルB2:B6をカバーし、列の1/4程度の幅でスクロールバーを作成します。
  • Excel 2007では、開発タブをクリックし、挿入をクリックし、フォームコントロールセクションでスクロールバーをクリックします。
  • スクロールバーを右クリックし、フォーマットコントロールをクリックします。
  • 次の情報を入力し、OKをクリックします。
    • 現在の値ボックスに1と入力します。
    • 最小値ボックスに1と入力します。この値は、スクロールバーの上部をリスト内の最初のアイテムに制限します。
    • 最大値ボックスに20と入力します。この数はリスト内のエントリの最大数を指定します。
    • 増分変更ボックスに1と入力します。この値は、スクロールバーが現在の値を増分変更する数を制御します。
    • ページ変更ボックスに5と入力します。このエントリは、スクロールバー内のスクロールボックスのいずれかの側をクリックした場合に、現在の値が増分変更される量を制御します。
    • リストで選択されたアイテムに応じてセルG1に数値を入力する場合、セルリンクボックスにG1と入力します。
  • スクロールバーが選択されていないことを確認するために、どこかのセルをクリックします。

スクロールバーの上または下のコントロールをクリックすると、セルG1はスクロールバーの現在の値に増分変更を足したり引いたりした数値に更新されます。

Aspose.Cells for Python via .NETを使用して

ShapeCollectionクラスは、ワークシートにスクロールバーコントロールを追加するために使用されるadd_scroll_barというメソッドを提供します。このメソッドはAspose.Cells.Drawing.ScrollBarオブジェクトを返します。Aspose.Cells.Drawing.ScrollBarクラスはスクロールバーを表します。いくつかの重要なメンバーがあります:

  • linked_cellプロパティは、スクロールバーにリンクされたセルを指定します。
  • maxプロパティは、スクロールバー範囲の最大値を指定します。
  • minプロパティは、スクロールバー範囲の最小値を指定します。
  • incremental_changeプロパティは、スクロールバーが1行スクロールされたときの値の量を指定します。
  • shadowプロパティは、スクロールバーに3Dの影があるかどうかを示します。
  • current_valueプロパティは、スクロールバーの現在の値を指定します。
  • page_changeプロパティは、スクロールバー内のスクロールボックスのいずれかの側をクリックした場合に、現在の値が増分変更される量を指定します。

以下の例は、ワークシートにスクロールバーを追加する方法を示しています。

from aspose.cells import Workbook
from aspose.cells.drawing import PlacementType
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Get the first worksheet.
worksheet = excelbook.worksheets[0]
# Invisible the gridlines of the worksheet.
worksheet.is_gridlines_visible = False
# Get the worksheet cells.
cells = worksheet.cells
# Input a value into A1 cell.
cells.get("A1").put_value(1)
# Set the font color of the cell.
cells.get("A1").get_style().font.color = Color.maroon
# Set the font text bold.
cells.get("A1").get_style().font.is_bold = True
# Set the number format.
cells.get("A1").get_style().number = 1
# Add a scrollbar control.
scrollbar = worksheet.shapes.add_scroll_bar(0, 0, 1, 0, 125, 20)
# Set the placement type of the scrollbar.
scrollbar.placement = PlacementType.FREE_FLOATING
# Set the linked cell for the control.
scrollbar.linked_cell = "A1"
# Set the maximum value.
scrollbar.max = 20
# Set the minimum value.
scrollbar.min = 1
# Set the incr. change for the control.
scrollbar.incremental_change = 1
# Set the page change attribute.
scrollbar.page_change = 5
# Set it 3-D shading.
scrollbar.shadow = True
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

ワークシートでグループコントロールにグループボックスコントロールを追加する

特定のグループに所属するラジオボタンやその他のコントロールを実装する必要がある場合は、グループボックスまたは長方形コントロールを含めることによって実装できます。これらの2つのオブジェクトのいずれかがグループのデリミタとして機能します。これらの形を追加した後は、2つ以上のラジオボタンやその他のグループオブジェクトを追加できます。

Microsoft Excel の使用

ワークシートにグループボックスコントロールを配置し、その中にコントロールを配置するには:

  • フォームを開始するには、メインメニューで表示をクリックし、ツールバーフォームをクリックします。
  • フォームツールバーで、グループボックスをクリックし、ワークシート上に長方形を描きます。
  • ボックスのキャプション文字列を入力します。
  • フォームツールバーで、オプションボタンをクリックし、グループボックス内のキャプション文字列の真下をクリックします。
  • 再度フォームツールバーで、オプションボタンをクリックし、前のラジオボタンの下にグループボックス内をクリックします。
  • もう一度フォームツールバーで、オプションボタンをクリックし、前のラジオボタンの下にグループボックス内をクリックします。

Aspose.Cells for Python via .NETを使用して

ShapeCollectionクラスは、ワークシートにグループボックスを追加し、コントロールをグループ化するためのadd_group_boxというメソッドを提供します。このメソッドはAspose.Cells.Drawing.GroupBoxオブジェクトを返します。また、groupクラスのShapeCollectionメソッドは、形をグループ化し、Shape配列をパラメータとして取り、GroupShapeオブジェクトを返します。Aspose.Cells.Drawing.GroupBoxクラスはグループボックスを表します。いくつかの重要なメンバーがあります:

  • textプロパティは、グループボックスのキャプション文字列を指定します。
  • shadowプロパティは、グループボックスに3Dの影があるかどうかを示します。

以下の例は、ワークシートにグループボックスを追加し、コントロールをグループ化する方法を示しています。

from aspose.cells import Workbook
from aspose.cells.drawing import MsoLineDashStyle, PlacementType
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)
# Instantiate a new Workbook.
excelbook = Workbook()
# Add a group box to the first worksheet.
box = excelbook.worksheets[0].shapes.add_group_box(1, 0, 1, 0, 300, 250)
# Set the caption of the group box.
box.text = "Age Groups"
box.placement = PlacementType.FREE_FLOATING
# Make it 2-D box.
box.shadow = False
# Add a radio button.
radio1 = excelbook.worksheets[0].shapes.add_radio_button(3, 0, 2, 0, 30, 110)
# Set its text string.
radio1.text = "20-29"
# Set A1 cell as a linked cell for the radio button.
radio1.linked_cell = "A1"
# Make the radio button 3-D.
radio1.shadow = True
# Set the weight of the radio button.
radio1.line.weight = 4.0
# Set the dash style of the radio button.
radio1.line.dash_style = MsoLineDashStyle.SOLID
# Add another radio button.
radio2 = excelbook.worksheets[0].shapes.add_radio_button(6, 0, 2, 0, 30, 110)
# Set its text string.
radio2.text = "30-39"
# Set A1 cell as a linked cell for the radio button.
radio2.linked_cell = "A1"
# Make the radio button 3-D.
radio2.shadow = True
# Set the weight of the radio button.
radio2.line.weight = 4.0
# Set the dash style of the radio button.
radio2.line.dash_style = MsoLineDashStyle.SOLID
# Add another radio button.
radio3 = excelbook.worksheets[0].shapes.add_radio_button(9, 0, 2, 0, 30, 110)
# Set its text string.
radio3.text = "40-49"
# Set A1 cell as a linked cell for the radio button.
radio3.linked_cell = "A1"
# Make the radio button 3-D.
radio3.shadow = True
# Set the weight of the radio button.
radio3.line.weight = 4.0
# Set the dash style of the radio button.
radio3.line.dash_style = MsoLineDashStyle.SOLID
# Get the shapes.
shapeobjects = [box, radio1, radio2, radio3]
# Group the shapes.
group = excelbook.worksheets[0].shapes.group(shapeobjects)
# Save the excel file.
excelbook.save(dataDir + "book1.out.xls")

高度なトピック