コントロールの管理
紹介
開発者はテキストボックス、チェックボックス、ラジオボタン、コンボボックス、ラベル、ボタン、ライン、四角形、円弧、楕円、スピンボタン、スクロールバー、グループボックスなどの異なる図形オブジェクトを追加できます。Aspose.Cellsには、すべての図形オブジェクトを含むAspose.Cells.Drawing名前空間が提供されています。ただし、まだサポートされていないいくつかの図形オブジェクトや形状があります。これらの図形オブジェクトはMicrosoft Excelでデザインされたスプレッドシートに作成し、その後Aspose.Cellsに読み込むことができます。Aspose.Cellsは、デザイナースプレッドシートからこれらの図形オブジェクトを読み込み、生成されたファイルに書き込むことができます。
ワークシートにテキストボックスコントロールを追加
レポートで重要な情報を強調する一つの方法は、テキストボックスを使用することです。たとえば、企業名を強調するためにテキストを追加したり、最も売り上げの高い地理的地域を示すために使用したりします。Aspose.Cellsは、新しいテキストボックスをコレクションに追加するために使用されるTextBoxCollectionクラスを提供しています。別のTextBoxクラスもあり、すべての種類の設定を定義するために使用されるテキストボックスを表しています。いくつか重要なメンバーがあります:
- TextFrameプロパティは、テキストボックスの内容を調整するために使用されるMsoTextFrameオブジェクトを返します。
- Placementプロパティは配置タイプを指定します。
- Fontプロパティはフォント属性を指定します。
- AddHyperlinkメソッドは、テキストボックスにハイパーリンクを追加します。
- FillFormatプロパティは、テキストボックスの塗りつぶし形式を設定するために使用されるMsoFillFormatオブジェクトを返します。
- LineFormatプロパティは、テキストボックスのラインのスタイルと太さを通常設定するために使用されるMsoLineFormatオブジェクトを返します。
- Textプロパティは、テキストボックスの入力テキストを指定します。
次の例では、ブックの最初のワークシートに2つのテキストボックスを作成します。最初のテキストボックスはさまざまなフォーマット設定で整備されています。2番目はシンプルなものです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add a new textbox to the collection. | |
int textboxIndex = worksheet.TextBoxes.Add(2, 1, 160, 200); | |
// Get the textbox object. | |
Aspose.Cells.Drawing.TextBox textbox0 = worksheet.TextBoxes[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.FreeFloating; | |
// Set the font color. | |
textbox0.Font.Color = Color.Blue; | |
// Set the font to bold. | |
textbox0.Font.IsBold = true; | |
// Set the font size. | |
textbox0.Font.Size = 14; | |
// Set font attribute to italic. | |
textbox0.Font.IsItalic = true; | |
// Add a hyperlink to the textbox. | |
textbox0.AddHyperlink("http:// Www.aspose.com/"); | |
// Get the filformat of the textbox. | |
Aspose.Cells.Drawing.FillFormat fillformat = textbox0.Fill; | |
// Get the lineformat type of the textbox. | |
Aspose.Cells.Drawing.LineFormat lineformat = textbox0.Line; | |
// Set the line weight. | |
lineformat.Weight = 6; | |
// Set the dash style to squaredot. | |
lineformat.DashStyle = MsoLineDashStyle.SquareDot; | |
// Add another textbox. | |
textboxIndex = worksheet.TextBoxes.Add(15, 4, 85, 120); | |
// Get the second textbox. | |
Aspose.Cells.Drawing.TextBox textbox1 = worksheet.TextBoxes[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.MoveAndSize; | |
// Save the excel file. | |
workbook.Save(dataDir + "book1.out.xls"); |
デザイナースプレッドシート内のテキストボックスコントロールの操作
Aspose.Cellsでは、デザイナースプレッドシート内のテキストボックスにアクセスして操作することもできます。Worksheet.TextBoxesプロパティを使用して、シート内のテキストボックスのコレクションを取得します。
次の例では、上記の例で作成したMicrosoft Excelファイルを使用しています。2つのテキストボックスのテキストを取得し、2番目のテキストボックスのテキストを変更してファイルを保存します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook. | |
// Open the existing excel file. | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Get the first textbox object. | |
Aspose.Cells.Drawing.TextBox textbox0 = worksheet.TextBoxes[0]; | |
// Obtain the text in the first textbox. | |
string text0 = textbox0.Text; | |
// Get the second textbox object. | |
Aspose.Cells.Drawing.TextBox textbox1 = worksheet.TextBoxes[1]; | |
// Obtain the text in the second textbox. | |
string 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"); |
ワークシートにチェックボックスコントロールを追加する
チェックボックスは、ユーザーが真偽またははい・いいえなどの2つのオプションから選択する方法を提供したい場合に便利です。Aspose.Cellsを使用すると、ワークシートでチェックボックスを使用できます。たとえば、特定の取得を考慮するかどうかを伴う財務予測ワークシートを作成した場合、そのワークシートの上部にチェックボックスを配置したいと思うかもしれません。その後、このチェックボックスの状態を他のセルにリンクすることができます。つまり、チェックボックスが選択されている場合、セルの値はTrueになり、選択されていない場合、セルの値はFalseになります。
Microsoft Excel の使用
ワークシートにチェックボックスコントロールを配置するには、次の手順に従います。
- フォームツールバーが表示されていることを確認します。
- フォームツールバーのチェックボックスツールをクリックします。
- ワークシートエリアで、チェックボックスとチェックボックスの横に表示されるラベルを定義するためにクリックしてドラッグします。
- チェックボックスが配置されたら、マウスカーソルをラベル領域に移動してラベルを変更します。
- セルリンクフィールドで、このチェックボックスをリンクするセルのアドレスを指定します。
- OK をクリックします。
Aspose.Cellsの使用
Aspose.Cellsには新しいチェックボックスをコレクションに追加するために使用されるCheckBoxCollectionクラスが提供されています。重要なメンバーを持つ他のクラスAspose.Cells.Drawing.CheckBoxもあります。
- LinkedCellプロパティは、チェックボックスにリンクされるセルを指定します。
- Textプロパティは、チェックボックスに関連付けられたテキスト文字列を指定します。これはチェックボックスのラベルです。
- Valueプロパティは、チェックボックスが選択されているかどうかを指定します。
次の例では、ワークシートにチェックボックスを追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add a checkbox to the first worksheet in the workbook. | |
int index = excelbook.Worksheets[0].CheckBoxes.Add(5, 5, 100, 120); | |
// Get the checkbox object. | |
Aspose.Cells.Drawing.CheckBox checkbox = excelbook.Worksheets[0].CheckBoxes[index]; | |
// Set its text string. | |
checkbox.Text = "Click it!"; | |
// Put a value into B1 cell. | |
excelbook.Worksheets[0].Cells["B1"].PutValue("LnkCell"); | |
// Set B1 cell as a linked cell for the checkbox. | |
checkbox.LinkedCell = "B1"; | |
// Check the checkbox by default. | |
checkbox.Value = true; | |
// Save the excel file. | |
excelbook.Save(dataDir + "book1.out.xls"); |
ワークシートにラジオボタンコントロールを追加する
ラジオボタン、またはオプションボタンは、円形のボックスからなるコントロールです。ユーザーはラウンドボックスを選択することで決定を行います。ラジオボタンは通常、他のラジオボタンに伴って表示され、グループとして振る舞います。ユーザーは1つのボタンのみを選択することで、どのボタンが有効か決定します。ユーザーが1つのボタンをクリックすると、それは選択されます。グループ内の1つのボタンが選択されると、同じグループのボタンは空になります。
Microsoft Excel の使用
ワークシートにラジオボタンコントロールを配置するには、次の手順に従います。
- フォーム ツールバーが表示されていることを確認します。
- オプションボタンツールをクリックします。
- ワークシートで、オプションボタンとオプションボタンの横に表示されるラベルを定義するためにクリックしてドラッグします。
- ワークシートにラジオボタンを配置したら、マウスカーソルをラベル領域に移動してラベルを変更します。
- セルリンクフィールドで、このラジオボタンがリンクされるセルのアドレスを指定します。
- OK をクリックします。
Aspose.Cellsの使用
Aspose.Cells.Drawing.ShapeCollectionクラスには、ワークシートにラジオボタンコントロールを追加するために使用されるAddRadioButtonというメソッドがあります。このメソッドはAspose.Cells.Drawing.RadioButtonオブジェクトを返します。また、Aspose.Cells.Drawing.RadioButtonクラスもあります。
- LinkedCellプロパティは、ラジオボタンにリンクされるセルを指定します。
- Textプロパティは、ラジオボタンに関連付けられたテキスト文字列を指定します。これはラジオボタンのラベルです。
- IsCheckedプロパティは、ラジオボタンが選択されているかどうかを指定します。
- FillFormatプロパティは、ラジオボタンの塗りつぶし形式を指定します。
- LineFormatプロパティは、オプションボタンの線の形式スタイルを指定します。
次の例では、ワークシートにラジオボタンを追加する方法を示しています。例では、3つの年齢グループを表すラジオボタンが追加されています。
ワークシートにコンボボックスコントロールを追加する
データの入力を容易にするか、定義した項目にエントリを制限するためには、ワークシートの他のセルからコンパイルされる有効なエントリのコンボボックス、またはドロップダウンリストを作成できます。セルのドロップダウンリストを作成すると、そのセルの隣に矢印が表示されます。そのセルに情報を入力するには、矢印をクリックし、その後、欲しいエントリをクリックします。
Microsoft Excel の使用
ワークシートにコンボボックスコントロールを配置するには、次の手順に従います:
- フォーム ツールバーが表示されていることを確認します。
- コンボボックス ツールをクリックします。
- ワークシートエリアで、コンボボックスを保持する四角形を定義するためにクリックしてドラッグします。
- コンボボックスがワークシートに配置されたら、コントロールを右クリックして コントロールの書式設定 をクリックし、入力範囲を指定します。
- セルリンク フィールドで、このコンボボックスをリンクするセルのアドレスを指定します。
- OK をクリックします。
Aspose.Cellsの使用
クラス Aspose.Cells.Drawing.ShapeCollection は AddComboBox という名前のメソッドを提供し、これはワークシートにコンボボックスコントロールを追加するために使用されます。このメソッドは Aspose.Cells.Drawing.ComboBox オブジェクトを返します。Aspose.Cells.Drawing.ComboBox クラスはコンボボックスを表します。いくつかの重要なメンバを持っています:
- LinkedCell プロパティはコンボボックスにリンクされたセルを指定します。
- InputRange プロパティはコンボボックスを埋めるために使用されるワークシートのセル範囲を指定します。
- DropDownLines プロパティはドロップダウン部分に表示されるリスト行の数を指定します。
- Shadow プロパティはコンボボックスが 3D シェーディングを持っているかどうかを示します。
次の例は、ワークシートにコンボボックスを追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Get the worksheet cells collection. | |
Cells cells = sheet.Cells; | |
// Input a value. | |
cells["B3"].PutValue("Employee:"); | |
// Set it bold. | |
cells["B3"].GetStyle().Font.IsBold = true; | |
// Input some values that denote the input range | |
// For the combo box. | |
cells["A2"].PutValue("Emp001"); | |
cells["A3"].PutValue("Emp002"); | |
cells["A4"].PutValue("Emp003"); | |
cells["A5"].PutValue("Emp004"); | |
cells["A6"].PutValue("Emp005"); | |
cells["A7"].PutValue("Emp006"); | |
// Add a new combo box. | |
Aspose.Cells.Drawing.ComboBox comboBox = sheet.Shapes.AddComboBox(2, 0, 2, 0, 22, 100); |
ワークシートにラベルコントロールを追加する
ラベルはスプレッドシートの内容に関するユーザーへの情報提供手段です。Aspose.Cells を使用すると、ワークシートにラベルを追加および操作することができます。クラス ShapeCollection は、ワークシートにラベルコントロールを追加するために使用する AddLabel という名前のメソッドを提供します。このメソッドは Label オブジェクトを返します。Label クラスはワークシート内のラベルを表します。いくつかの重要なメンバを持っています:
次の例は、ワークシートにラベルを追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the workbook. | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add a new label to the worksheet. | |
Aspose.Cells.Drawing.Label label = sheet.Shapes.AddLabel(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.FreeFloating; | |
// Saves the file. | |
workbook.Save(dataDir + "book1.out.xls"); |
ワークシートにリストボックスコントロールを追加する
リストボックスコントロールは、単一または複数のアイテム選択を可能にするリストコントロールを作成します。
Microsoft Excel の使用
ワークシートにリストボックスコントロールを配置するには:
- フォーム ツールバーが表示されていることを確認します。
- リストボックス ツールをクリックします。
- ワークシートエリアで、リストボックスを保持する四角形を定義するためにクリックしてドラッグします。
- リストボックスがワークシートに配置されたら、コントロールを右クリックして コントロールの書式設定 をクリックし、入力範囲を指定します。
- セルリンク フィールドで、このリストボックスをリンクするセルのアドレスを指定し、選択タイプ(単一、複数、拡張)属性を設定します。
- OK をクリックします。
Aspose.Cellsの使用
クラス ShapeCollection は、ワークシートにリストボックスコントロールを追加するために使用される AddListBox という名前のメソッドを提供します。このメソッドは Aspose.Cells.Drawing.ListBox オブジェクトを返します。ListBox クラスはリストボックスを表します。いくつかの重要なメンバを持っています:
- LinkedCell メソッドはリストボックスにリンクされたセルを指定します。
- InputRange メソッドはリストボックスを埋めるために使用されるワークシートのセル範囲を指定します。
- SelectionType メソッドはリストボックスの選択モードを指定します。
- Shadow メソッドはリストボックスに3Dシェーディングがあるかどうかを示します。
次の例は、ワークシートにリストボックスを追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Get the worksheet cells collection. | |
Cells cells = sheet.Cells; | |
// Input a value. | |
cells["B3"].PutValue("Choose Dept:"); | |
// Set it bold. | |
cells["B3"].GetStyle().Font.IsBold = true; | |
// Input some values that denote the input range | |
// For the list box. | |
cells["A2"].PutValue("Sales"); | |
cells["A3"].PutValue("Finance"); | |
cells["A4"].PutValue("MIS"); | |
cells["A5"].PutValue("R&D"); | |
cells["A6"].PutValue("Marketing"); | |
cells["A7"].PutValue("HRA"); | |
// Add a new list box. | |
Aspose.Cells.Drawing.ListBox listBox = sheet.Shapes.AddListBox(2, 0, 3, 0, 122, 100); | |
// Set the placement type. | |
listBox.Placement = PlacementType.FreeFloating; | |
// Set the linked cell. | |
listBox.LinkedCell = "A1"; | |
// Set the input range. | |
listBox.InputRange = "A2:A7"; | |
// Set the selection tyle. | |
listBox.SelectionType = 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 の使用
ボタンコントロールをワークシートに配置するには:
- フォーム ツールバーが表示されていることを確認します。
- ボタン ツールをクリックします。
- ワークシート領域でクリックしてドラッグして、ボタンを配置する矩形を定義します。
- リストボックスがワークシートに配置されたら、コントロールを右クリックして フォーマットコントロール を選択し、VBAマクロを指定し、フォント、配置、サイズ、余白などに関連する属性を設定します。
- OK をクリックします。
Aspose.Cellsの使用
ShapeCollection クラスは、ボタンコントロールをワークシートに追加するための AddButton という名前のメソッドを提供します。このメソッドは Aspose.Cells.Drawing.Button オブジェクトを返します。クラス Aspose.Cells.Drawing.Button はボタンを表します。いくつかの重要なメンバーがあります:
- Text プロパティはボタンのキャプションを指定します。
- Font プロパティはボタンコントロールのラベルのフォント属性を指定します。
- Placement プロパティはボタンがワークシートのセルにアタッチされる方法を指定します。
- AddHyperlink プロパティはボタンコントロールにハイパーリンクを追加します。ボタンをクリックすると関連するURLに移動します。
次の例は、ワークシートにボタンを追加する方法を示しています。
ワークシートにラインコントロールを追加する
Microsoft Excel の使用
- 描画 ツールバーで オートシェイプ をクリックし、ライン を指して、希望のラインスタイルを選択します。
- ドラッグしてラインを描きます。
- 次のいずれかを行います。
- ラインを開始点から15度の角度で制限するには、ドラッグしながら SHIFT キーを押します。
- 最初の端点から異なる方向にラインを長くするには、ドラッグしながら CTRL キーを押します。
Aspose.Cellsの使用
ShapeCollection クラスは、ワークシートにラインシェイプを追加するために使用される AddLine という名前のメソッドを提供します。このメソッドは LineShape オブジェクトを返します。クラス LineShape はラインを表します。いくつかの重要なメンバーがあります:
- LineFormat メソッドはラインのフォーマットを指定します。
- Placement メソッドはラインがワークシートのセルにアタッチされる方法を指定します。
次の例は、ワークシートにラインを追加する方法を示しています。異なるスタイルで3つのラインが作成されます。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add a new line to the worksheet. | |
Aspose.Cells.Drawing.LineShape line1 = worksheet.Shapes.AddLine(5, 0, 1, 0, 0, 250); | |
// Set the line dash style | |
line1.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Set the placement. | |
line1.Placement = PlacementType.FreeFloating; | |
// Add another line to the worksheet. | |
Aspose.Cells.Drawing.LineShape line2 = worksheet.Shapes.AddLine(7, 0, 1, 0, 85, 250); | |
// Set the line dash style. | |
line2.Line.DashStyle = MsoLineDashStyle.DashLongDash; | |
// Set the weight of the line. | |
line2.Line.Weight = 4; | |
// Set the placement. | |
line2.Placement = PlacementType.FreeFloating; | |
// Add the third line to the worksheet. | |
Aspose.Cells.Drawing.LineShape line3 = worksheet.Shapes.AddLine(13, 0, 1, 0, 0, 250); | |
// Set the line dash style | |
line3.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Set the placement. | |
line3.Placement = PlacementType.FreeFloating; | |
// Make the gridlines invisible in the first worksheet. | |
workbook.Worksheets[0].IsGridlinesVisible = false; | |
// Save the excel file. | |
workbook.Save(dataDir + "book1.out.xls"); |
ラインに矢印を追加する
Aspose.Cellsでは、矢印付きの直線を描画することもできます。直線に矢印を追加したり、直線のフォーマットを行ったりすることができます。例えば、直線の色を変更したり、直線の太さやスタイルを指定したりすることができます。
次の例は、ラインに矢印を追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add a line to the worksheet | |
Aspose.Cells.Drawing.LineShape line2 = worksheet.Shapes.AddLine(7, 0, 1, 0, 85, 250); | |
// Set the line color | |
line2.Line.FillType = FillType.Solid; | |
line2.Line.SolidFill.Color = Color.Blue; | |
// Set the weight of the line. | |
line2.Line.Weight = 3; | |
// Set the placement. | |
line2.Placement = PlacementType.FreeFloating; | |
// Set the line arrows. | |
line2.Line.EndArrowheadWidth = MsoArrowheadWidth.Medium; | |
line2.Line.EndArrowheadStyle = MsoArrowheadStyle.Arrow; | |
line2.Line.EndArrowheadLength = MsoArrowheadLength.Medium; | |
line2.Line.BeginArrowheadStyle = MsoArrowheadStyle.ArrowDiamond; | |
line2.Line.BeginArrowheadLength = MsoArrowheadLength.Medium; | |
// Make the gridlines invisible in the first worksheet. | |
workbook.Worksheets[0].IsGridlinesVisible = false; | |
// Save the excel file. | |
workbook.Save(dataDir + "book1.out.xlsx"); |
ワークシートに長方形コントロールを追加する
Aspose.Cellsを使用すると、ワークシートに長方形の図形を描画できます。長方形や正方形などを作成できます。また、コントロールの塗りつぶしの色や境界線の色を書式設定することができます。たとえば、長方形の色を変更したり、シェーディングの色を設定したり、必要に応じて長方形の太さやスタイルを指定することができます。
Microsoft Excel の使用
- 描画ツールバーで、長方形をクリックします。
- 長方形を描画するには、ドラッグします。
- 次のいずれかを行います。
- 長方形を開始点から正方形に描画するには、ドラッグしながらSHIFTキーを押し続けます。
- 長方形を中心点から描画するには、ドラッグしながらCTRLキーを押し続けます。
Aspose.Cellsの使用
クラスShapeCollectionには、ワークシートに長方形を追加するためのAddRectangleという名前のメソッドがあります。このメソッドはAspose.Cells.Drawing.RectangleShapeオブジェクトを返します。クラスAspose.Cells.Drawing.RectangleShapeは長方形を表します。いくつか重要なメンバーがあります。
- LineFormatプロパティは長方形の線の書式属性を指定します。
- PlacementプロパティはPlacementTypeを指定し、長方形がワークシートのセルにアタッチされる方法を示します。
- FillFormatプロパティは長方形の塗りつぶしの書式スタイルを指定します。
次の例は、ワークシートに長方形を追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add a rectangle control. | |
Aspose.Cells.Drawing.RectangleShape rectangle = excelbook.Worksheets[0].Shapes.AddRectangle(3, 0, 2, 0, 70, 130); | |
// Set the placement of the rectangle. | |
rectangle.Placement = PlacementType.FreeFloating; | |
// Set the line weight. | |
rectangle.Line.Weight = 4; | |
// Set the dash style of the rectangle. | |
rectangle.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Save the excel file. | |
excelbook.Save(dataDir + "book1.out.xls"); |
ワークシートに円弧コントロールを追加する
Aspose.Cellsを使用すると、ワークシートに円弧の図形を描画できます。シンプルな円弧や塗りつぶした円弧を作成できます。また、コントロールの塗りつぶしの色や境界線の色を書式設定することができます。たとえば、円弧の色を指定/変更したり、シェーディングの色を設定したり、必要に応じて図形の太さやスタイルを指定することができます。
Microsoft Excel の使用
- 図形の自動スタイルで、円弧をクリックします。
- 円弧を描画するには、ドラッグします。
Aspose.Cellsの使用
クラスShapeCollectionには、ワークシートに円弧形状を追加するためのAddArcという名前のメソッドがあります。このメソッドはAspose.Cells.Drawing.ArcShapeオブジェクトを返します。クラスAspose.Cells.Drawing.ArcShapeは円弧を表します。いくつか重要なメンバーがあります。
- LineFormatプロパティは円弧形状の線の書式属性を指定します。
- PlacementプロパティはPlacementTypeを指定し、円弧がワークシートのセルにアタッチされる方法を示します。
- FillFormatプロパティは形状の塗りつぶし形式スタイルを指定します。
- LowerRightRowプロパティは右下の行インデックスを指定します。
- LowerRightColumnプロパティは右下の列インデックスを指定します。
次の例は、ワークシートに円弧形状を追加する方法を示しています。この例では、塗りつぶしの円弧形状とシンプルな円弧形状の2つを作成します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add an arc shape. | |
Aspose.Cells.Drawing.ArcShape arc1 = excelbook.Worksheets[0].Shapes.AddArc(2, 0, 2, 0, 130, 130); | |
// Set the fill shape color | |
arc1.Fill.FillType = FillType.Solid; | |
arc1.Fill.SolidFill.Color = Color.Blue; | |
// Set the placement of the arc. | |
arc1.Placement = PlacementType.FreeFloating; | |
// Set the line weight. | |
arc1.Line.Weight = 1; | |
// Set the dash style of the arc. | |
arc1.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Add another arc shape. | |
Aspose.Cells.Drawing.ArcShape arc2 = excelbook.Worksheets[0].Shapes.AddArc(9, 0, 2, 0, 130, 130); | |
// Set the line color | |
arc2.Line.FillType = FillType.Solid; | |
arc2.Line.SolidFill.Color = Color.Blue; | |
// Set the placement of the arc. | |
arc2.Placement = PlacementType.FreeFloating; | |
// Set the line weight. | |
arc2.Line.Weight = 1; | |
// Set the dash style of the arc. | |
arc2.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Save the excel file. | |
excelbook.Save(dataDir + "book1.out.xls"); |
ワークシートに楕円コントロールを追加する
Aspose.Cellsを使用すると、ワークシートに楕円の図形を描画できます。単純な楕円や塗りつぶした楕円形状を作成し、コントロールの塗りつぶしの色や境界線の色を書式設定できます。たとえば、楕円の色を指定/変更したり、シェーディングの色を設定したり、必要に応じて図形の太さやスタイルを指定することができます。
Microsoft Excel の使用
- 図形ツールバーで、楕円をクリックします。
- 楕円を描画するには、ドラッグします。
- 以下のいずれか、または両方を行います。
- 楕円を開始点から円として描画するには、ドラッグしながらSHIFTキーを押し続けます。
- 楕円を中心点から描画するには、ドラッグしながらCTRLキーを押し続けます。
Aspose.Cellsの使用
クラスShapeCollectionは、ワークシートに楕円形を追加するために使用されるAddOvalというメソッドを提供します。このメソッドはAspose.Cells.Drawing.Ovalオブジェクトを返します。クラスAspose.Cells.Drawing.Ovalは楕円形を表し、いくつかの重要なメンバーがあります。
- LineFormatプロパティは楕円形の線形式属性を指定します。
- Placementプロパティはワークシート内のセルに楕円形を接続する方法を指定します。
- FillFormatプロパティは形状の塗りつぶし形式スタイルを指定します。
- LowerRightRowプロパティは右下の行インデックスを指定します。
- LowerRightColumnプロパティは右下の列インデックスを指定します。
次の例は、ワークシートに楕円形を追加する方法を示しています。この例では、塗りつぶしの楕円形と単純な円形の2つの楕円形を作成します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add an oval shape. | |
Aspose.Cells.Drawing.Oval oval1 = excelbook.Worksheets[0].Shapes.AddOval(2, 0, 2, 0, 130, 160); | |
// Set the placement of the oval. | |
oval1.Placement = PlacementType.FreeFloating; | |
// Set the line weight. | |
oval1.Line.Weight = 1; | |
// Set the dash style of the oval. | |
oval1.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Add another oval (circle) shape. | |
Aspose.Cells.Drawing.Oval oval2 = excelbook.Worksheets[0].Shapes.AddOval(9, 0, 2, 15, 130, 130); | |
// Set the placement of the oval. | |
oval2.Placement = PlacementType.FreeFloating; | |
// Set the line weight. | |
oval2.Line.Weight = 1; | |
// Set the dash style of the oval. | |
oval2.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Save the excel file. | |
excelbook.Save(dataDir + "book1.out.xls"); |
ワークシートにスピンボックスコントロールを追加
スピンボックスは、ボタン(スピンボタンと呼ばれる)に取り付けられたテキストボックスで、テキストボックスの値を逐次的に変更するためにクリックする上向き矢印と下向き矢印で構成されます。スピンボックスを使用することで、財務モデルの入力がモデルの出力にどのように影響するかを確認できます。スピンボタンを特定の入力セルに取り付けることができます。スピンボタンの上向き矢印または下向き矢印をクリックすると、対象の入力セル内の整数値が増減します。Aspose.Cellsを使用すると、ワークシートにスピンボックスを作成できます。
Microsoft Excel の使用
ワークシートにスピンボックスコントロールを配置するには:
- フォームツールバーが表示されていることを確認します。
- スピンボックスツールをクリックします。
- ワークシート領域で、スピンボックスを保持する矩形を定義するためにクリックしてドラッグします。
- スピンボックスをワークシートに配置したら、コントロールを右クリックして フォーマットコントロール をクリックし、最大値、最小値、増分値を指定します。
- セルリンク フィールドに、このスピンボックスをリンクするセルのアドレスを指定します。
- OK をクリックします。
Aspose.Cellsの使用
クラスShapeCollectionは、ワークシートにスピンボックスコントロールを追加するために使用されるAddSpinnerというメソッドを提供します。このメソッドはAspose.Cells.Drawing.Spinnerオブジェクトを返します。クラスAspose.Cells.Drawing.Spinnerはスピンボックスを表し、いくつかの重要なメンバーがあります。
- LinkedCellプロパティは、スピンボックスにリンクされたセルを指定します。
- Maxプロパティは、スピンボックス範囲の最大値を指定します。
- Minプロパティは、スピンボックス範囲の最小値を指定します。
- IncrementalChangeプロパティは、スピンボックスが1行スクロールされる値の量を指定します。
- Shadowプロパティは、スピンボックスに3Dシェーディングがあるかどうかを示します。
- CurrentValueプロパティは、スピンボックスの現在の値を指定します。
次の例は、ワークシートにスピンボックスを追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet worksheet = excelbook.Worksheets[0]; | |
// Get the worksheet cells. | |
Cells cells = worksheet.Cells; | |
// Input a string value into A1 cell. | |
cells["A1"].PutValue("Select Value:"); | |
// Set the font color of the cell. | |
cells["A1"].GetStyle().Font.Color = Color.Red; | |
// Set the font text bold. | |
cells["A1"].GetStyle().Font.IsBold = true; | |
// Input value into A2 cell. | |
cells["A2"].PutValue(0); | |
// Set the shading color to black with solid background. | |
cells["A2"].GetStyle().ForegroundColor = Color.Black; | |
cells["A2"].GetStyle().Pattern = BackgroundType.Solid; | |
// Set the font color of the cell. | |
cells["A2"].GetStyle().Font.Color = Color.White; | |
// Set the font text bold. | |
cells["A2"].GetStyle().Font.IsBold = true; | |
// Add a spinner control. | |
Aspose.Cells.Drawing.Spinner spinner = excelbook.Worksheets[0].Shapes.AddSpinner(1, 0, 1, 0, 20, 18); | |
// Set the placement type of the spinner. | |
spinner.Placement = PlacementType.FreeFloating; | |
// Set the linked cell for the control. | |
spinner.LinkedCell = "A2"; | |
// Set the maximum value. | |
spinner.Max = 10; | |
// Set the minimum value. | |
spinner.Min = 0; | |
// Set the incr. change for the control. | |
spinner.IncrementalChange = 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の使用
ShapeCollectionクラスは、ワークシートにスクロールバーコントロールを追加するために使用されるAddScrollBarというメソッドを提供します。このメソッドはAspose.Cells.Drawing.ScrollBarオブジェクトを返します。Aspose.Cells.Drawing.ScrollBarクラスはスクロールバーを表します。いくつかの重要なメンバーがあります:
- LinkedCellプロパティは、スクロールバーにリンクされたセルを指定します。
- Maxプロパティは、スクロールバー範囲の最大値を指定します。
- Minプロパティは、スクロールバー範囲の最小値を指定します。
- IncrementalChangeプロパティは、スクロールバーが1行スクロールされたときの値の量を指定します。
- Shadowプロパティは、スクロールバーに3Dの影があるかどうかを示します。
- CurrentValueプロパティは、スクロールバーの現在の値を指定します。
- PageChangeプロパティは、スクロールバー内のスクロールボックスのいずれかの側をクリックした場合に、現在の値が増分変更される量を指定します。
以下の例は、ワークシートにスクロールバーを追加する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet worksheet = excelbook.Worksheets[0]; | |
// Invisible the gridlines of the worksheet. | |
worksheet.IsGridlinesVisible = false; | |
// Get the worksheet cells. | |
Cells cells = worksheet.Cells; | |
// Input a value into A1 cell. | |
cells["A1"].PutValue(1); | |
// Set the font color of the cell. | |
cells["A1"].GetStyle().Font.Color = Color.Maroon; | |
// Set the font text bold. | |
cells["A1"].GetStyle().Font.IsBold = true; | |
// Set the number format. | |
cells["A1"].GetStyle().Number = 1; | |
// Add a scrollbar control. | |
Aspose.Cells.Drawing.ScrollBar scrollbar = worksheet.Shapes.AddScrollBar(0, 0, 1, 0, 125, 20); | |
// Set the placement type of the scrollbar. | |
scrollbar.Placement = PlacementType.FreeFloating; | |
// Set the linked cell for the control. | |
scrollbar.LinkedCell = "A1"; | |
// Set the maximum value. | |
scrollbar.Max = 20; | |
// Set the minimum value. | |
scrollbar.Min = 1; | |
// Set the incr. change for the control. | |
scrollbar.IncrementalChange = 1; | |
// Set the page change attribute. | |
scrollbar.PageChange = 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の使用
ShapeCollectionクラスは、ワークシートにグループボックスを追加し、コントロールをグループ化するためのAddGroupBoxというメソッドを提供します。このメソッドはAspose.Cells.Drawing.GroupBoxオブジェクトを返します。また、GroupクラスのShapeCollectionメソッドは、形をグループ化し、Shape配列をパラメータとして取り、GroupShapeオブジェクトを返します。Aspose.Cells.Drawing.GroupBoxクラスはグループボックスを表します。いくつかの重要なメンバーがあります:
以下の例は、ワークシートにグループボックスを追加し、コントロールをグループ化する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add a group box to the first worksheet. | |
Aspose.Cells.Drawing.GroupBox box = excelbook.Worksheets[0].Shapes.AddGroupBox(1, 0, 1, 0, 300, 250); | |
// Set the caption of the group box. | |
box.Text = "Age Groups"; | |
box.Placement = PlacementType.FreeFloating; | |
// Make it 2-D box. | |
box.Shadow = false; | |
// Add a radio button. | |
Aspose.Cells.Drawing.RadioButton radio1 = excelbook.Worksheets[0].Shapes.AddRadioButton(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.LinkedCell = "A1"; | |
// Make the radio button 3-D. | |
radio1.Shadow = true; | |
// Set the weight of the radio button. | |
radio1.Line.Weight = 4; | |
// Set the dash style of the radio button. | |
radio1.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Add another radio button. | |
Aspose.Cells.Drawing.RadioButton radio2 = excelbook.Worksheets[0].Shapes.AddRadioButton(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.LinkedCell = "A1"; | |
// Make the radio button 3-D. | |
radio2.Shadow = true; | |
// Set the weight of the radio button. | |
radio2.Line.Weight = 4; | |
// Set the dash style of the radio button. | |
radio2.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Add another radio button. | |
Aspose.Cells.Drawing.RadioButton radio3 = excelbook.Worksheets[0].Shapes.AddRadioButton(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.LinkedCell = "A1"; | |
// Make the radio button 3-D. | |
radio3.Shadow = true; | |
// Set the weight of the radio button. | |
radio3.Line.Weight = 4; | |
// Set the dash style of the radio button. | |
radio3.Line.DashStyle = MsoLineDashStyle.Solid; | |
// Get the shapes. | |
Aspose.Cells.Drawing.Shape[] shapeobjects = new Aspose.Cells.Drawing.Shape[] { box, radio1, radio2, radio3 }; | |
// Group the shapes. | |
Aspose.Cells.Drawing.GroupShape group = excelbook.Worksheets[0].Shapes.Group(shapeobjects); | |
// Save the excel file. | |
excelbook.Save(dataDir + "book1.out.xls"); |