コントロールの管理
序章
開発者は、テキスト ボックス、チェック ボックス、ラジオ ボタン、コンボ ボックス、ラベル、ボタン、線、長方形、弧、楕円、スピナー、スクロール バー、グループ ボックスなど、さまざまな描画オブジェクトを追加できます。すべての描画オブジェクト。ただし、まだサポートされていない描画オブジェクトまたは図形がいくつかあります。 Microsoft Excel を使用してデザイナー スプレッドシートでこれらの描画オブジェクトを作成し、デザイナー スプレッドシートを Aspose.Cells にインポートします。
テキスト ボックス コントロールをワークシートに追加する
レポートで重要な情報を強調する 1 つの方法は、テキスト ボックスを使用することです。たとえば、テキストを追加して、会社名を強調したり、売上高が最も多い地域を示したりします。Aspose.Cells は、TextBoxCollectionコレクションに新しいテキスト ボックスを追加するために使用されるクラス。別のクラスがあり、テキストボックス、すべてのタイプの設定を定義するために使用されるテキスト ボックスを表します。いくつかの重要なメンバーがあります。
- のテキストフレームプロパティはMsoTextFrameテキスト ボックスの内容を調整するために使用されるオブジェクト。
- の配置プロパティは配置タイプを指定します。
- のフォントプロパティは、フォント属性を指定します。
- のハイパーリンクを追加メソッドは、テキスト ボックスのハイパーリンクを追加します。
- のFillFormatプロパティはMsoFillFormatテキスト ボックスの塗りつぶし形式を設定するために使用されるオブジェクト。
- のLineFormatプロパティはMsoLineFormat通常、テキスト ボックスの行のスタイルと太さに使用されるオブジェクト。
- の文章プロパティは、テキスト ボックスの入力テキストを指定します。
次の例では、ブックの最初のワークシートに 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"); |
Designer スプレッドシートでのテキスト ボックス コントロールの操作
Aspose.Cells では、デザイナー ワークシートのテキスト ボックスにアクセスして操作することもできます。使用Worksheet.TextBoxesシート内の 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"); |
ワークシートへのチェック ボックス コントロールの追加
チェック ボックスは、ユーザーが true または false などの 2 つのオプションから選択できるようにする場合に便利です。はい、もしくは、いいえ。 Aspose.Cells では、ワークシートでチェック ボックスを使用できます。たとえば、特定の買収を説明できるかどうかを説明できる財務予測ワークシートを作成したとします。この場合、ワークシートの上部にチェック ボックスを配置することができます。次に、このチェック ボックスのステータスを別のセルにリンクして、チェック ボックスがオンの場合にセルの値が True になるようにします。選択されていない場合、セルの値は False です。
Microsoft エクセルを使う
ワークシートにチェック ボックス コントロールを配置するには、次の手順を実行します。
- フォーム ツールバーが表示されていることを確認します。
- クリックチェックボックスフォーム ツールバーのツール。
- ワークシート領域で、クリック アンド ドラッグして、チェック ボックスとチェック ボックスの横のラベルを保持する四角形を定義します。
- チェック ボックスを配置したら、マウス カーソルをラベル領域に移動し、ラベルを変更します。
- の中にCell リンクフィールドで、このチェック ボックスをリンクするセルのアドレスを指定します。
- クリックわかった.
Aspose.Cells を使用
Aspose.Cells はCheckBoxコレクションこのクラスは、コレクションに新しいチェック ボックスを追加するために使用されます。別のクラスがあり、Aspose.Cells.Drawing.CheckBox、チェック ボックスを表します。いくつかの重要なメンバーがあります。
- のリンクされたセルプロパティは、チェック ボックスにリンクされているセルを指定します。
- の文章プロパティは、チェック ボックスに関連付けられたテキスト文字列を指定します。チェックボックスのラベルです。
- の価値プロパティは、チェック ボックスをオンにするかどうかを指定します。
次の例は、ワークシートにチェックボックスを追加する方法を示しています。
// 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 エクセルを使う
ワークシートにラジオ ボタン コントロールを配置するには、次の手順に従います。
- を確認してくださいフォームツールバーが表示されます。
- クリックオプションボタン道具。
- ワークシートで、クリック アンド ドラッグして、オプション ボタンとオプション ボタンの横のラベルを保持する四角形を定義します。
- ラジオ ボタンがワークシートに配置されたら、マウス カーソルをラベル領域に移動し、ラベルを変更します。
- の中にCell リンクフィールドで、このラジオ ボタンをリンクするセルのアドレスを指定します。
- クリックわかった.
Aspose.Cells を使用
Aspose.Cells.Drawing.ShapeCollectionクラスは、という名前のメソッドを提供します追加ラジオボタン、ワークシートにラジオ ボタン コントロールを追加するために使用されます。メソッドはAspose.Cells.Drawing.RadioButton物体。クラスAspose.Cells.Drawing.RadioButtonオプションボタンを表します。いくつかの重要なメンバーがあります。
- のリンクされたセルプロパティは、ラジオ ボタンにリンクされているセルを指定します。
- の文章プロパティは、ラジオ ボタンに関連付けられたテキスト文字列を指定します。ラジオボタンのラベルです。
- のチェック済みプロパティは、ラジオ ボタンをオンにするかどうかを指定します。
- のFillFormatプロパティは、ラジオ ボタンの塗りつぶし形式を指定します。
- のLineFormatプロパティは、オプション ボタンの線の書式スタイルを指定します。
次の例は、ラジオ ボタンをワークシートに追加する方法を示しています。この例では、年齢層を表す 3 つのラジオ ボタンを追加します。
コンボ ボックス コントロールをワークシートに追加する
データ入力を容易にするため、または定義した特定の項目にエントリを制限するために、コンボ ボックス、またはワークシートの他の場所のセルからコンパイルされた有効なエントリのドロップダウン リストを作成できます。セルのドロップダウン リストを作成すると、そのセルの横に矢印が表示されます。そのセルに情報を入力するには、矢印をクリックし、目的のエントリをクリックします。
Microsoft エクセルを使う
ワークシートにコンボ ボックス コントロールを配置するには、次の手順を実行します。
- を確認してくださいフォームツールバーが表示されます。
- クリックしてくださいコンボボックス道具。
- ワークシート領域で、クリック アンド ドラッグして、コンボ ボックスを保持する四角形を定義します。
- コンボ ボックスがワークシートに配置されたら、コントロールを右クリックしてクリックします。フォーマット制御入力範囲を指定します。
- の中にCell リンクフィールドで、このコンボ ボックスをリンクするセルのアドレスを指定します。
- クリックわかった.
Aspose.Cells を使用
のAspose.Cells.Drawing.ShapeCollectionクラスは、という名前のメソッドを提供しますAddComboBox 、コンボ ボックス コントロールをワークシートに追加するために使用されます。メソッドはAspose.Cells.Drawing.ComboBox物体。クラスAspose.Cells.Drawing.ComboBoxコンボボックスを表します。いくつかの重要なメンバーがあります。
- のリンクされたセルプロパティは、コンボ ボックスにリンクされているセルを指定します。
- の入力範囲プロパティは、コンボ ボックスを埋めるために使用されるセルのワークシート範囲を指定します。
- のドロップダウンラインプロパティは、コンボ ボックスのドロップダウン部分に表示されるリストの行数を指定します。
- の影プロパティは、コンボ ボックスに 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 を使用すると、ワークシートでラベルを追加および操作できます。のシェイプコレクションクラスは、という名前のメソッドを提供しますラベルを追加、ワークシートにラベル コントロールを追加するために使用されます。メソッドはラベル物体。クラスラベルワークシートのラベルを表します。いくつかの重要なメンバーがあります。
次の例は、ワークシートにラベルを追加する方法を示しています。
// 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"); |
ワークシートへのリスト ボックス コントロールの追加
リスト ボックス コントロールは、1 つまたは複数の項目を選択できるリスト コントロールを作成します。
Microsoft エクセルを使う
ワークシートにリスト ボックス コントロールを配置するには:
- を確認してくださいフォームツールバーが表示されます。
- クリックしてくださいリストボックス道具。
- ワークシート領域で、クリック アンド ドラッグして、リスト ボックスを保持する四角形を定義します。
- リスト ボックスがワークシートに配置されたら、コントロールを右クリックしてクリックします。フォーマット制御入力範囲を指定します。
- の中にCell リンクフィールドで、このリスト ボックスをリンクするセルのアドレスを指定し、選択タイプ (Single、Multi、Extend) 属性を設定します。
- クリックわかった.
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供しますAddListBox 、リスト ボックス コントロールをワークシートに追加するために使用されます。メソッドはAspose.Cells.Drawing.ListBox物体。クラスリストボックスリストボックスを表します。いくつかの重要なメンバーがあります。
- のリンクされたセルメソッドは、リスト ボックスにリンクされているセルを指定します。
- の入力範囲メソッドは、リスト ボックスを埋めるために使用されるセルのワークシート範囲を指定します。
- の選択タイプメソッドは、リスト ボックスの選択モードを指定します。
- の影メソッドは、リスト ボックスに 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 エクセルを使う
ワークシートにボタン コントロールを配置するには:
- を確認してくださいフォームツールバーが表示されます。
- クリックしてくださいボタン道具。
- ワークシート領域で、クリック アンド ドラッグして、ボタンを保持する四角形を定義します。
- リスト ボックスがワークシートに配置されたら、コントロールを右クリックし、フォーマット制御、次に VBA マクロと属性に関連するフォント、配置、サイズ、余白などを指定します。
- クリックわかった.
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供します追加ボタンボタン コントロールをワークシートに追加するために使用します。メソッドはAspose.Cells.Drawing.Button物体。クラスAspose.Cells.Drawing.Buttonボタンを表します。いくつかの重要なメンバーがあります。
- の文章プロパティは、ボタンのキャプションを指定します。
- のフォントプロパティは、ボタン コントロールのラベルのフォント属性を指定します。
- の配置プロパティは、配置タイプ、ボタンがワークシートのセルに接続される方法。
- のハイパーリンクを追加プロパティは、ボタン コントロールのハイパーリンクを追加します。ボタンをクリックすると、関連する URL に移動します。
次の例は、ワークシートにボタンを追加する方法を示しています。
ワークシートへの行コントロールの追加
Microsoft エクセルを使う
- 上で描くツールバー、クリックオートシェイプ、 指し示すラインをクリックして、必要な線のスタイルを選択します。
- ドラッグして線を引きます。
- 次のいずれかまたは両方を実行します。
- 開始点から 15 度の角度で描画するように線を制限するには、Shift キーを押しながらドラッグします。
- 最初の終点から反対方向に線を伸ばすには、CTRL キーを押しながらドラッグします。
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供します行を追加、ワークシートに線の形状を追加するために使用されます。メソッドは線の形状物体。クラス線の形状線を表します。いくつかの重要なメンバーがあります。
- のLineFormatメソッドは、行の形式を指定します。
- の配置メソッドは配置タイプ、ワークシート内のセルに線が接続される方法。
次の例は、ワークシートに行を追加する方法を示しています。スタイルの異なる 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 エクセルを使う
- 上で描くツールバー、クリック矩形.
- ドラッグして長方形を描きます。
- 次のいずれかまたは両方を実行します。
- 開始点から四角形を描くように長方形を制限するには、Shift キーを押しながらドラッグします。
- 中心点から長方形を描くには、CTRL キーを押しながらドラッグします。
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供します長方形を追加、ワークシートに四角形を追加するために使用されます。メソッドは戻りますAspose.Cells.Drawing.RectangleShape物体。クラスAspose.Cells.Drawing.RectangleShape長方形を表します。いくつかの重要なメンバーがあります。
- のLineFormatプロパティは、四角形の線の書式属性を指定します。
- の配置プロパティは、配置タイプ、四角形がワークシートのセルに接続される方法。
- の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 エクセルを使う
- 上で描くツールバー、クリックアークの中にオートシェイプ.
- ドラッグして円弧を描きます。
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供します追加円弧、円弧形状をワークシートに追加するために使用されます。メソッドはAspose.Cells.Drawing.ArcShape物体。クラスAspose.Cells.Drawing.ArcShape円弧を表します。いくつかの重要なメンバーがあります。
- のLineFormatプロパティは、円弧形状の線形式属性を指定します。
- の配置プロパティは、配置タイプ、アークがワークシートのセルに接続される方法。
- のFillFormatプロパティは、形状の塗りつぶし形式のスタイルを指定します。
- の右下の行プロパティは、右下隅の行インデックスを指定します。
- の右下の列プロパティは、右下隅の列インデックスを指定します。
次の例は、アーク形状をワークシートに追加する方法を示しています。この例では、2 つの円弧形状を作成します。1 つは塗りつぶされ、もう 1 つは単純です。
// 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 エクセルを使う
- 上で描くツールバー、クリックオーバル.
- ドラッグして楕円を描きます。
- 次のいずれかまたは両方を実行します。
- 楕円が始点から円を描くように制限するには、Shift キーを押しながらドラッグします。
- 中心点から楕円を描くには、CTRL キーを押しながらドラッグします。
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供しますAddOval 、ワークシートに楕円形を追加するために使用されます。メソッドはAspose.Cells.Drawing.Oval物体。クラスAspose.Cells.Drawing.Oval楕円形を表します。いくつかの重要なメンバーがあります。
- のLineFormatプロパティは、楕円形のライン フォーマット属性を指定します。
- の配置プロパティは、配置タイプ、楕円がワークシートのセルに接続される方法。
- のFillFormatプロパティは、形状の塗りつぶし形式のスタイルを指定します。
- の右下の行プロパティは、右下隅の行インデックスを指定します。
- の右下の列プロパティは、右下隅の列インデックスを指定します。
次の例は、楕円形をワークシートに追加する方法を示しています。この例では、2 つの楕円形を作成します。1 つは塗りつぶされた楕円形で、もう 1 つは単純な円です。
// 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 エクセルを使う
ワークシートにスピン ボックス コントロールを配置するには:
- を確認してくださいフォームツールバーが表示されます。
- クリックスピナー道具。
- ワークシート領域で、クリック アンド ドラッグして、スピナーを保持する長方形を定義します。
- スピナーがワークシートに配置されたら、コントロールを右クリックしてフォーマット制御最大値、最小値、増分値を指定します。
- の中にCell リンクフィールドで、このスピン ボックスをリンクするセルのアドレスを指定します。
- クリックわかった.
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供しますAddSpinner、スピン ボックス コントロールをワークシートに追加するために使用されます。メソッドはAspose.Cells.Drawing.Spinner物体。クラスAspose.Cells.Drawing.Spinnerスピンボックスを表します。いくつかの重要なメンバーがあります。
- のリンクされたセルプロパティは、スピン ボックスにリンクされているセルを指定します。
- のマックスプロパティは、スピン ボックスの範囲の最大値を指定します。
- の分プロパティは、スピン ボックスの範囲の最小値を指定します。
- の増分変更プロパティは、ライン スクロールによってスピナーがインクリメントされる値の量を指定します。
- の影プロパティは、スピン ボックスに 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); | |
// 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 2003 以前のバージョンでスクロール バーを追加するには、スクロール・バーボタンフォームツールバーをクリックし、高さがセル B2:B6 をカバーし、列の幅の約 4 分の 1 のスクロール バーを作成します。
- Excel 2007 でスクロール バーを追加するには、デベロッパータブ、クリック入れるをクリックし、スクロール・バーフォーム コントロール セクションにあります。
- スクロール バーを右クリックし、フォーマット制御.
- 次の情報を入力して、わかった:
- の中に現在の価値ボックス、タイプ 1。
- の中に最小値ボックスに 1 を入力します。この値は、スクロール バーの上部をリストの最初の項目に制限します。
- の中に最大値ボックスに 20 と入力します。この数は、リスト内のエントリの最大数を指定します。
- の中に増分変更ボックスに 1 を入力します。この値は、スクロール バー コントロールが現在の値をインクリメントする数を制御します。
- の中にページ変更ボックスに 5 と入力します。このエントリは、スクロール ボックスのいずれかの側のスクロール バー内をクリックした場合に、現在の値がどれだけ増加するかを制御します。 セル G1 に数値を入力するには (リストで選択されている項目によって異なります)、Cell リンク箱。
- スクロール バーが選択されないように任意のセルをクリックします。
スクロール バーのアップまたはダウン コントロールをクリックすると、セル G1 は、スクロール バーの現在の値にスクロール バーの増分変化を加えた値または引いた値を示す数値に更新されます。
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供しますAddScrollBar 、スクロール バー コントロールをワークシートに追加するために使用されます。メソッドはAspose.Cells.Drawing.ScrollBar物体。クラスAspose.Cells.Drawing.ScrollBarスクロールバーを表します。いくつかの重要なメンバーがあります。
- のリンクされたセルプロパティは、スクロール バーにリンクされているセルを指定します。
- のマックスプロパティは、スクロール バーの範囲の最大値を指定します。
- の分プロパティは、スクロール バーの範囲の最小値を指定します。
- の増分変更プロパティは、行スクロールでスクロール バーがインクリメントされる値の量を指定します。
- の影プロパティは、スクロール バーに 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); | |
// 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"); |
ワークシートのグループ コントロールへの GroupBox コントロールの追加
特定のグループに属するラジオ ボタンやその他のコントロールを実装する必要がある場合があります。グループ ボックスまたは四角形のコントロールを含めることで実装できます。これら 2 つのオブジェクトのいずれかが、グループの区切り文字として機能します。これらの図形の 1 つを追加した後、2 つ以上のラジオ ボタンまたは他のグループ オブジェクトを追加できます。
Microsoft エクセルを使う
ワークシートにグループ ボックス コントロールを配置し、その中にコントロールを配置するには:
- フォームを開始するには、メイン メニューで意見、 に続くツールバーとフォーム.
- 上でフォームツールバーで、グループボックスそしてワークシートに長方形を描きます。
- ボックスのキャプション文字列を入力します。
- 上でフォームツールバー、クリックオプションボタンをクリックし、グループボックスキャプション文字列のすぐ下。
- からフォームツールバーを再度クリックし、オプションボタンをクリックし、グループボックス最初のラジオボタンの下。
- もう一度フォームツールバー、クリックオプションボタンをクリックし、グループボックス前のラジオボタンの下。
Aspose.Cells を使用
のシェイプコレクションクラスは、という名前のメソッドを提供しますグループボックスを追加、グループ ボックス コントロールをワークシートに追加するために使用されます。メソッドはAspose.Cells.Drawing.GroupBox物体。さらに、グループの方法シェイプコレクションクラスは形状をグループ化します。形配列をパラメータとして返し、グループシェイプ物体。クラス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"); |