コントロールの管理
序章
開発者は、テキスト ボックス、チェック ボックス、ラジオ ボタン、コンボ ボックス、ラベル、ボタン、線、長方形、弧、楕円、スピナー、スクロール バー、グループ ボックスなど、さまざまな描画オブジェクトを追加できます。すべての描画オブジェクト。ただし、まだサポートされていない描画オブジェクトまたは図形がいくつかあります。 Microsoft Excel を使用してデザイナー スプレッドシートでこれらの描画オブジェクトを作成し、デザイナー スプレッドシートを Aspose.Cells にインポートします。
TextBox コントロールをワークシートに追加する
レポートで重要な情報を強調する 1 つの方法は、テキスト ボックスを使用することです。たとえば、テキストを追加して、会社名を強調したり、売上高が最も多い地域を示したりします。Aspose.Cells は、コレクションに新しいテキスト ボックスを追加するために使用される TextBoxes クラスを提供します。別のクラスがあり、テキストボックス、すべてのタイプの設定を定義するために使用されるテキスト ボックスを表します。いくつかの重要なメンバーがあります。
- のgetTextFrameメソッドはMsoTextFrameテキスト ボックスの内容を調整するために使用されるオブジェクト。
- のsetPlacement method は配置タイプを指定します。
- のsetFontメソッドは、フォント属性を指定します。
- の[addハイパーリンク](https://reference.aspose.com/cells/java/com.aspose.cells/textbox#addHyperlink(java.lang.String)メソッドは、テキスト ボックスのハイパーリンクを追加します。
- のFillFormatプロパティリターンMsoFillFormatテキスト ボックスの塗りつぶし形式を設定するために使用されるオブジェクト。
- のLineFormatプロパティはMsoLineFormat通常、テキスト ボックスの行のスタイルと太さに使用されるオブジェクト。
- のセットテキストメソッドは、テキスト ボックスの入力テキストを指定します。
次の例では、ブックの最初のワークシートに 2 つのテキスト ボックスを作成します。最初のテキスト ボックスには、さまざまな書式設定が用意されています。 2 つ目は単純なものです。
コードを実行すると、次の出力が生成されます。
ワークシートに 2 つのテキスト ボックスが作成されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AddingTextBoxControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the textbox object. | |
int textboxIndex = worksheet.getTextBoxes().add(2, 1, 160, 200); | |
TextBox textbox0 = worksheet.getTextBoxes().get(textboxIndex); | |
// Fill the text. | |
textbox0.setText("ASPOSE______The .NET & JAVA Component Publisher!"); | |
// Set the placement. | |
textbox0.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the font color. | |
textbox0.getFont().setColor(Color.getBlue()); | |
// Set the font to bold. | |
textbox0.getFont().setBold(true); | |
// Set the font size. | |
textbox0.getFont().setSize(14); | |
// Set font attribute to italic. | |
textbox0.getFont().setItalic(true); | |
// Add a hyperlink to the textbox. | |
textbox0.addHyperlink("http://www.aspose.com/"); | |
// Get the filformat of the textbox. | |
FillFormat fillformat = textbox0.getFill(); | |
// Set the fillcolor. | |
fillformat.setOneColorGradient(Color.getSilver(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Get the lineformat type of the textbox. | |
LineFormat lineformat = textbox0.getLine(); | |
// Set the line style. | |
lineformat.setDashStyle(MsoLineStyle.THIN_THICK); | |
// Set the line weight. | |
lineformat.setWeight(6); | |
// Set the dash style to squaredot. | |
lineformat.setDashStyle(MsoLineDashStyle.SQUARE_DOT); | |
// Get the second textbox. | |
TextBox textbox1 = (com.aspose.cells.TextBox) worksheet.getShapes().addShape(MsoDrawingType.TEXT_BOX, 15, 0, 4, | |
0, 85, 120); | |
// Input some text to it. | |
textbox1.setText("This is another simple text box"); | |
// Set the placement type as the textbox will move and resize with cells. | |
textbox1.setPlacement(PlacementType.MOVE_AND_SIZE); | |
// Save the excel file. | |
workbook.save(dataDir + "AddingTextBoxControl_out.xls"); |
Designer スプレッドシートでのテキスト ボックス コントロールの操作
Aspose.Cells では、デザイナー ワークシートのテキスト ボックスにアクセスして操作することもできます。使用Worksheet.getTextBoxesシート内の textboxes コレクションを取得するプロパティ。
次の例では、上記の例で作成した Microsoft Excel ファイル (tsttextboxes.xls) を使用しています。 2 つのテキスト ボックスのテキスト文字列を取得し、2 番目のテキスト ボックスのテキストを変更してファイルを保存します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ManipulatingTextBoxControls.class); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the first textbox object. | |
com.aspose.cells.TextBox textbox0 = worksheet.getTextBoxes().get(0); | |
// Obtain the text in the first textbox. | |
String text0 = textbox0.getText(); | |
System.out.println(text0); | |
// Get the second textbox object. | |
com.aspose.cells.TextBox textbox1 = worksheet.getTextBoxes().get(1); | |
// Obtain the text in the second textbox. | |
String text1 = textbox1.getText(); | |
// Change the text of the second textbox. | |
textbox1.setText("This is an alternative text"); | |
// Save the excel file. | |
workbook.save(dataDir + "tsttextboxes1.xls"); |
CheckBox コントロールをワークシートに追加する
チェック ボックスは、ユーザーが true または false などの 2 つのオプションから選択できるようにする場合に便利です。はい、もしくは、いいえ。 Aspose.Cells では、ワークシートでチェック ボックスを使用できます。たとえば、特定の買収を説明できるかどうかを説明できる財務予測ワークシートを作成したとします。この場合、ワークシートの上部にチェック ボックスを配置することができます。次に、このチェック ボックスのステータスを別のセルにリンクして、チェック ボックスがオンの場合にセルの値が True になるようにします。選択されていない場合、セルの値は False です。
Microsoft エクセルを使う
ワークシートにチェック ボックス コントロールを配置するには、次の手順を実行します。
- フォーム ツールバーが表示されていることを確認します。
- クリックチェックボックスフォーム ツールバーのツール。
- ワークシート領域で、クリック アンド ドラッグして、チェック ボックスとチェック ボックスの横のラベルを保持する四角形を定義します。
- チェック ボックスを配置したら、マウス カーソルをラベル領域に移動し、ラベルを変更します。
- の中にCell リンクフィールドで、このチェック ボックスをリンクするセルのアドレスを指定します。
- クリックわかった.
Aspose.Cells を使用
Aspose.Cells はCheckBoxコレクションこのクラスは、コレクションに新しいチェック ボックスを追加するために使用されます。別のクラスがあり、Aspose.Cells.Drawing.CheckBox、チェック ボックスを表します。いくつかの重要なメンバーがあります。
- のsetLinkedCellメソッドは、チェック ボックスにリンクされているセルを指定します。
- のセットテキストメソッドは、チェック ボックスに関連付けられたテキスト文字列を指定します。チェックボックスのラベルです。
- のsetValueメソッドは、チェック ボックスをオンにするかどうかを指定します。
次の例は、ワークシートにチェックボックスを追加する方法を示しています。以下の出力は、コードの実行後に生成されます。
ワークシートに CheckBox が追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingCheckBoxControl.class); | |
// Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Add a checkbox to the first worksheet in the workbook. | |
int checkBoxIndex = worksheet.getCheckBoxes().add(5, 5, 100, 120); | |
CheckBox checkBox = worksheet.getCheckBoxes().get(checkBoxIndex); | |
// Set its text string. | |
checkBox.setText("Check it!"); | |
// Put a value into B1 cell. | |
worksheet.getCells().get("B1").setValue("LnkCell"); | |
// Set B1 cell as a linked cell for the checkbox. | |
checkBox.setLinkedCell("=B1"); | |
// Save the excel file. | |
workbook.save(dataDir + "tstcheckboxes.xls"); |
RadioButton コントロールをワークシートに追加する
ラジオ ボタンまたはオプション ボタンは、丸いボックスで構成されるコントロールです。ユーザーは、丸いボックスを選択して決定を下します。ラジオ ボタンには通常、常にではありませんが、他のボタンが付随しています。このようなラジオ ボタンは、グループとして表示され、動作します。ユーザーは、そのうちの 1 つだけを選択することによって、どのボタンが有効であるかを決定します。ユーザーが 1 つのボタンをクリックすると、それが満たされます。グループ内の 1 つのボタンを選択すると、同じグループのボタンは空になります。
Microsoft エクセルを使う
ワークシートにラジオ ボタン コントロールを配置するには、次の手順に従います。
- を確認してくださいフォームツールバーが表示されます。
- クリックオプションボタン道具。
- ワークシートで、クリック アンド ドラッグして、オプション ボタンとオプション ボタンの横のラベルを保持する四角形を定義します。
- ラジオ ボタンがワークシートに配置されたら、マウス カーソルをラベル領域に移動し、ラベルを変更します。
- の中にCell リンクフィールドで、このラジオ ボタンをリンクするセルのアドレスを指定します。
- クリックわかった.
Aspose.Cells を使用
のシェイプコレクションクラスは、ワークシートにラジオ ボタン コントロールを追加するために使用できる addShape という名前のメソッドを提供します。このメソッドは、RadioButton オブジェクトを返す場合があります。クラス RadioButton は、オプション ボタンを表します。いくつかの重要なメンバーがあります。
- setLinkedCell メソッドは、ラジオ ボタンにリンクされるセルを指定します。
- setText メソッドは、ラジオ ボタンに関連付けられたテキスト文字列を指定します。ラジオボタンのラベルです。
- Checked プロパティは、ラジオ ボタンがチェックされているかどうかを指定します。
- setFillFormat メソッドは、ラジオ ボタンの塗りつぶし形式を指定します。
- setLineFormat メソッドは、オプション ボタンの線の書式スタイルを指定します。
次の例は、ラジオ ボタンをワークシートに追加する方法を示しています。この例では、年齢層を表す 3 つのラジオ ボタンを追加します。コードを実行すると、次の出力が生成されます。
ワークシートにいくつかの RadioButtons が追加されます
コンボ ボックス コントロールをワークシートに追加する
データ入力を容易にするため、または定義した特定の項目にエントリを制限するために、コンボ ボックス、またはワークシートの他の場所のセルからコンパイルされた有効なエントリのドロップダウン リストを作成できます。セルのドロップダウン リストを作成すると、そのセルの横に矢印が表示されます。そのセルに情報を入力するには、矢印をクリックし、目的のエントリをクリックします。
Microsoft エクセルを使う
ワークシートにコンボ ボックス コントロールを配置するには、次の手順を実行します。
- を確認してくださいフォームツールバーが表示されます。
- クリックしてくださいコンボボックス道具。
- ワークシート領域で、クリック アンド ドラッグして、コンボ ボックスを保持する四角形を定義します。
- コンボ ボックスがワークシートに配置されたら、コントロールを右クリックしてクリックします。フォーマット制御入力範囲を指定します。
- の中にCell リンクフィールドで、このコンボ ボックスをリンクするセルのアドレスを指定します。
- クリックわかった.
Aspose.Cells を使用
のシェイプコレクションクラスには、ワークシートにコンボ ボックス コントロールを追加するために使用できる addShape という名前のメソッドが用意されています。このメソッドは ComboBox オブジェクトを返すことができます。クラス ComboBox は、コンボ ボックスを表します。いくつかの重要なメンバーがあります。
- setLinkedCell メソッドは、コンボ ボックスにリンクされるセルを指定します。
- setInputRange メソッドは、コンボ ボックスを埋めるために使用されるセルのワークシート範囲を指定します。
- setDropDownLines メソッドは、コンボ ボックスのドロップダウン部分に表示されるリストの行数を指定します。
- setShadow メソッドは、コンボ ボックスに 3D シェーディングがあるかどうかを示します。
次の例は、ワークシートにコンボ ボックスを追加する方法を示しています。コードを実行すると、次の出力が生成されます。
ワークシートにコンボボックスが追加されました
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingComboBoxControl.class); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the worksheet cells collection. | |
Cells cells = sheet.getCells(); | |
// Input a value. | |
cells.get("B3").setValue("Employee:"); | |
Style style = cells.get("B3").getStyle(); | |
style.getFont().setBold(true); | |
// Set it bold. | |
cells.get("B3").setStyle(style); | |
// Input some values that denote the input range for the combo box. | |
cells.get("A2").setValue("Emp001"); | |
cells.get("A3").setValue("Emp002"); | |
cells.get("A4").setValue("Emp003"); | |
cells.get("A5").setValue("Emp004"); | |
cells.get("A6").setValue("Emp005"); | |
cells.get("A7").setValue("Emp006"); | |
// Add a new combo box. | |
com.aspose.cells.ComboBox comboBox = (com.aspose.cells.ComboBox) sheet.getShapes() | |
.addShape(MsoDrawingType.COMBO_BOX, 3, 0, 1, 0, 20, 100); | |
// Set the linked cell; | |
comboBox.setLinkedCell("A1"); | |
// Set the input range. | |
comboBox.setInputRange("=A2:A7"); | |
// Set no. of list lines displayed in the combo box's list portion. | |
comboBox.setDropDownLines(5); | |
// Set the combo box with 3-D shading. | |
comboBox.setShadow(true); | |
// AutoFit Columns | |
sheet.autoFitColumns(); | |
// Saves the file. | |
workbook.save(dataDir + "tstcombobox.xls"); |
ワークシートへのラベル コントロールの追加
ラベルは、スプレッドシートの内容に関する情報をユーザーに提供する手段です。 Aspose.Cells を使用すると、ワークシートでラベルを追加および操作できます。のシェイプコレクションクラスは、ワークシートにラベル コントロールを追加するために使用される addShape という名前のメソッドを提供します。このメソッドは Label オブジェクトを返します。クラス Label は、ワークシートのラベルを表します。いくつかの重要なメンバーがあります。
- setText メソッドは、ラベルのキャプション文字列を指定します。
- setPlacement メソッドは、ワークシートのセルにラベルを付ける方法である PlacementType を指定します。
次の例は、ワークシートにラベルを追加する方法を示しています。コードを実行すると、次の出力が生成されます。
ワークシートにラベルが追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AddingLabelControl.class) + "DrawingObjects/"; | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Add a new label to the worksheet. | |
com.aspose.cells.Label label = (com.aspose.cells.Label) sheet.getShapes().addShape(MsoDrawingType.LABEL, 2, 2, | |
2, 0, 60, 120); | |
// Set the caption of the label. | |
label.setText("This is a Label"); | |
// Set the Placement Type, the way the label is attached to the cells. | |
label.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill color of the label. | |
label.getFill().setOneColorGradient(Color.getYellow(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Saves the file. | |
workbook.save(dataDir + "AddingLabelControl_out.xls"); |
ワークシートへのリスト ボックス コントロールの追加
リスト ボックス コントロールは、1 つまたは複数の項目を選択できるリスト コントロールを作成します。
Microsoft エクセルを使う
ワークシートにリスト ボックス コントロールを配置するには:
- を確認してくださいフォームツールバーが表示されます。
- クリックしてくださいリストボックス道具。
- ワークシート領域で、クリック アンド ドラッグして、リスト ボックスを保持する四角形を定義します。
- リスト ボックスがワークシートに配置されたら、コントロールを右クリックしてクリックします。フォーマット制御入力範囲を指定します。
- の中にCell リンクフィールドで、このリスト ボックスをリンクするセルのアドレスを指定し、選択タイプ (Single、Multi、Extend) 属性を設定します。
- クリックわかった.
Aspose.Cells を使用
のシェイプコレクションクラスには、ワークシートにリスト ボックス コントロールを追加するために使用される addShape という名前のメソッドが用意されています。メソッドは ListBox オブジェクトを返します。クラス ListBox は、リスト ボックスを表します。いくつかの重要なメンバーがあります。
- setLinkedCell メソッドは、リスト ボックスにリンクされているセルを指定します。
- setInputRange メソッドは、リスト ボックスを埋めるために使用されるセルのワークシート範囲を指定します。
- setSelectionType メソッドは、リスト ボックスの選択モードを指定します。
- setShadow メソッドは、リスト ボックスに 3D シェーディングがあるかどうかを示します。
次の例は、ワークシートにリスト ボックスを追加する方法を示しています。コードを実行すると、次の出力が生成されます。
ワークシートにリスト ボックスが追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingListBoxControl.class); | |
// Create a new Workbook. | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet. | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Get the worksheet cells collection. | |
Cells cells = sheet.getCells(); | |
// Input a value. | |
cells.get("B3").setValue("Choose Dept:"); | |
Style style = cells.get("B3").getStyle(); | |
style.getFont().setBold(true); | |
// Set it bold. | |
cells.get("B3").setStyle(style); | |
// Input some values that denote the input range for the combo box. | |
cells.get("A2").setValue("Sales"); | |
cells.get("A3").setValue("Finance"); | |
cells.get("A4").setValue("MIS"); | |
cells.get("A5").setValue("R&D"); | |
cells.get("A6").setValue("Marketing"); | |
cells.get("A7").setValue("HRA"); | |
// Add a new list box. | |
com.aspose.cells.ListBox listBox = (com.aspose.cells.ListBox) sheet.getShapes() | |
.addShape(MsoDrawingType.LIST_BOX, 3, 3, 1, 0, 100, 122); | |
// Set the linked cell; | |
listBox.setLinkedCell("A1"); | |
// Set the input range. | |
listBox.setInputRange("=A2:A7"); | |
// Set the Placement Type, the way the list box is attached to the cells. | |
listBox.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the list box with 3-D shading. | |
listBox.setShadow(true); | |
// Set the selection type. | |
listBox.setSelectionType(SelectionType.SINGLE); | |
// AutoFit Columns | |
sheet.autoFitColumns(); | |
// Saves the file. | |
workbook.save(dataDir + "tstlistbox.xls"); |
ボタン コントロールをワークシートに追加する
ボタンは、いくつかのアクションを実行するのに役立ちます。場合によっては、VBA マクロをボタンに割り当てたり、ハイパーリンクを割り当てて Web ページを開くと便利です。
Microsoft エクセルを使う
ワークシートにボタン コントロールを配置するには:
- を確認してくださいフォームツールバーが表示されます。
- クリックしてくださいボタン道具。
- ワークシート領域で、クリック アンド ドラッグして、ボタンを保持する四角形を定義します。
- リスト ボックスがワークシートに配置されたら、コントロールを右クリックし、フォーマット制御、次に VBA マクロと属性に関連するフォント、配置、サイズ、余白などを指定します。
- クリックわかった.
Aspose.Cells を使用
のシェイプコレクションクラスは、ワークシートにボタン コントロールを追加するために使用される addShape という名前のメソッドを提供します。このメソッドは、Button オブジェクトを返す場合があります。クラス Button はボタンを表します。いくつかの重要なメンバーがあります。
- setText メソッドは、ボタンのキャプションを指定します。
- setPlacement メソッドは、ボタンがワークシートのセルに接続される方法である PlacementType を指定します。
- addHyperlink メソッドは、ボタン コントロールのハイパーリンクを追加します。ボタンをクリックすると、関連する URL に移動します。
次の例は、ワークシートにボタンを追加する方法を示しています。コードを実行すると、次の出力が生成されます
ワークシートにボタンが追加されます
ワークシートへの行コントロールの追加
Aspose.Cells を使用すると、ワークシートにオートシェイプを描画できます。簡単にラインを作ることができます。行をフォーマットすることもできます。たとえば、線の色を変更したり、必要に応じて線の太さとスタイルを指定したりできます。
Microsoft エクセルを使う
- 上で描くツールバー、クリックオートシェイプ、 指し示すラインをクリックして、必要な線のスタイルを選択します。
- ドラッグして線を引きます。
- 次のいずれかまたは両方を実行します。
- 開始点から 15 度の角度で描画するように線を制限するには、Shift キーを押しながらドラッグします。
- 最初の終点から反対方向に線を伸ばすには、CTRL キーを押しながらドラッグします。
Aspose.Cells を使用
のシェイプコレクションクラスには、ワークシートに線の形状を追加するために使用される addShape という名前のメソッドが用意されています。このメソッドは、LineShape オブジェクトを返す場合があります。クラス LineShape は線を表します。いくつかの重要なメンバーがあります。
- setDashStyle メソッドは、線の形式を指定します。
- setPlacement メソッドは、ワークシート内のセルに線を接続する方法である PlacementType を指定します。
次の例は、ワークシートに行を追加する方法を示しています。スタイルの異なる 3 つのラインを作成します。コードを実行すると、次の出力が生成されます
ワークシートにいくつかの行が追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AddingLineControl.class) + "DrawingObjects/"; | |
//Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
//Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Add a new line to the worksheet. | |
LineShape line1 = (LineShape)worksheet.getShapes().addShape(MsoDrawingType.LINE,5, 1,0,0, 0, 250); | |
line1.setHasLine(true); | |
//Set the line dash style | |
LineFormat shapeline = line1.getLine(); | |
shapeline.setDashStyle(MsoLineDashStyle.SOLID); | |
//Set the placement. | |
line1.setPlacement(PlacementType.FREE_FLOATING); | |
//Add another line to the worksheet. | |
LineShape line2 = (LineShape) worksheet.getShapes().addShape(MsoDrawingType.LINE, 7, 1,0,0, 85, 250); | |
line2.setHasLine(true); | |
//Set the line dash style. | |
shapeline = line2.getLine(); | |
shapeline.setDashStyle(MsoLineDashStyle.DASH_LONG_DASH); | |
shapeline.setWeight(4); | |
//Set the placement. | |
line2.setPlacement(PlacementType.FREE_FLOATING); | |
//Add the third line to the worksheet. | |
LineShape line3 = (LineShape)worksheet.getShapes().addShape(MsoDrawingType.LINE, 13, 1,0,0, 0, 250); | |
line3.setHasLine(true); | |
//Set the line dash style | |
shapeline = line1.getLine(); | |
shapeline.setDashStyle(MsoLineDashStyle.SOLID); | |
//Set the placement. | |
line3.setPlacement(PlacementType.FREE_FLOATING); | |
//Save the excel file. | |
workbook.save(dataDir + "tstlines.xls"); |
線に矢印を追加する
Aspose.Cells では、矢印の線を描くこともできます。線に矢印を追加し、線をフォーマットすることができます。たとえば、線の色を変更したり、線の太さとスタイルを指定したりできます。
次の例は、線に矢印を追加する方法を示しています。コードを実行すると、次の出力が生成されます。
ワークシートに矢印付きの線が追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AddinganArrowHead.class) + "DrawingObjects/"; | |
//Instantiate a new Workbook. | |
Workbook workbook = new Workbook(); | |
//Get the first worksheet in the book. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Add a line to the worksheet | |
LineShape line2 = (LineShape) worksheet.getShapes().addShape(MsoDrawingType.LINE, 7, 0, 1, 0, 85, 250); | |
//Set the line color | |
line2.getLine().setFillType(FillType.SOLID); | |
line2.getLine().getSolidFill().setColor(Color.getRed()); | |
//Set the weight of the line. | |
line2.getLine().setWeight(3); | |
//Set the placement. | |
line2.setPlacement(PlacementType.FREE_FLOATING); | |
//Set the line arrows. | |
line2.getLine().setEndArrowheadWidth(MsoArrowheadWidth.MEDIUM); | |
line2.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW); | |
line2.getLine().setEndArrowheadLength(MsoArrowheadLength.MEDIUM); | |
line2.getLine().setBeginArrowheadStyle(MsoArrowheadStyle.ARROW_DIAMOND); | |
line2.getLine().setBeginArrowheadLength(MsoArrowheadLength.MEDIUM); | |
//Make the gridlines invisible in the first worksheet. | |
workbook.getWorksheets().get(0).setGridlinesVisible(false); | |
//Save the excel file. | |
workbook.save(dataDir + "AddinganArrowHead_out.xlsx"); |
ワークシートへの四角形コントロールの追加
Aspose.Cells を使用すると、ワークシートに四角形を描画できます。長方形、正方形などを作成できます。また、コントロールの塗りつぶしの色と境界線の色をフォーマットすることもできます。たとえば、必要に応じて、長方形の色を変更したり、陰影の色を設定したり、長方形の太さとスタイルを指定したりできます。
Microsoft エクセルを使う
- 上で描くツールバー、クリック矩形.
- ドラッグして長方形を描きます。
- 次のいずれかまたは両方を実行します。
- 開始点から四角形を描くように長方形を制限するには、Shift キーを押しながらドラッグします。
- 中心点から長方形を描くには、CTRL キーを押しながらドラッグします。
Aspose.Cells を使用
のシェイプコレクションクラスは、ワークシートに四角形を追加するために使用される addShape という名前のメソッドを提供します。このメソッドは RectangleShape オブジェクトを返すことができます。クラス RectangleShape は長方形を表します。いくつかの重要なメンバーがあります。
- setLineFormat メソッドは、長方形の線フォーマット属性を指定します。
- setPlacement メソッドは PlacementType を指定します。これは、四角形がワークシートのセルに接続される方法です。
- FillFormat プロパティは、四角形の塗りつぶし形式のスタイルを指定します。
次の例は、ワークシートに四角形を追加する方法を示しています。コードを実行すると、次の出力が生成されます。
ワークシートに四角形が追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AddingRectangleControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add a rectangle control. | |
com.aspose.cells.RectangleShape rectangle = (com.aspose.cells.RectangleShape) excelbook.getWorksheets().get(0) | |
.getShapes().addShape(MsoDrawingType.RECTANGLE, 3, 2, 0, 0, 70, 130); | |
// Set the placement of the rectangle. | |
rectangle.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill format. | |
FillFormat fillformat = rectangle.getFill(); | |
fillformat.setOneColorGradient(Color.getOlive(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the line style. | |
LineFormat linestyle = rectangle.getLine(); | |
linestyle.setDashStyle(MsoLineStyle.THICK_THIN); | |
// Set the line weight. | |
linestyle.setWeight(4); | |
// Set the color of the line. | |
linestyle.setOneColorGradient(Color.getBlue(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the dash style of the rectangle. | |
linestyle.setDashStyle(MsoLineDashStyle.SOLID); | |
// Save the excel file. | |
excelbook.save(dataDir + "AddingRectangleControl_out.xls"); |
ワークシートへの円弧制御の追加
Aspose.Cells を使用すると、ワークシートに円弧を描くことができます。シンプルで塗りつぶされた円弧を作成できます。コントロールの塗りつぶしの色と境界線の色をフォーマットできます。たとえば、円弧の色を指定/変更したり、シェーディングの色を設定したり、必要に応じて形状の重みとスタイルを指定したりできます。
Microsoft エクセルを使う
- 上で描くツールバー、クリックアークの中にオートシェイプ.
- ドラッグして円弧を描きます。
Aspose.Cells を使用
のシェイプコレクションクラスは addShape という名前のメソッドを提供します。これはワークシートに円弧形状を追加するために使用されます。このメソッドは、ArcShape オブジェクトを返すことができます。クラス ArcShape は円弧を表します。いくつかの重要なメンバーがあります。
- setLineFormat メソッドは、円弧形状の線フォーマット属性を指定します。
- setPlacement メソッドは、アークがワークシートのセルに接続される方法である PlacementType を指定します。
- FillFormat プロパティは、図形の塗りつぶし形式のスタイルを指定します。
次の例は、アーク形状をワークシートに追加する方法を示しています。この例では、2 つの円弧形状を作成します。1 つは塗りつぶされ、もう 1 つは単純です。コードを実行すると、次の出力が生成されます
つの円弧形状がワークシートに追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AddingArcControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add an arc shape. | |
com.aspose.cells.ArcShape arc1 = (com.aspose.cells.ArcShape) excelbook.getWorksheets().get(0).getShapes() | |
.addShape(MsoDrawingType.ARC, 2, 2, 0, 0, 130, 130); | |
// Set the placement of the arc. | |
arc1.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill format. | |
FillFormat fillformat = arc1.getFill();// getFillFormat(); | |
fillformat.setOneColorGradient(Color.getLime(), 1, GradientStyleType.HORIZONTAL, 1); | |
//setForeColor(Color.getBlue()); | |
// Set the line style. | |
LineFormat lineformat = arc1.getLine();// getLineFormat(); | |
lineformat.setDashStyle(MsoLineStyle.SINGLE); //setStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat.setWeight(1); | |
// Set the color of the arc line. | |
lineformat.setOneColorGradient(Color.getLime(), 1, GradientStyleType.HORIZONTAL, 1); //setForeColor(Color.getBlue()); | |
// Set the dash style of the arc. | |
lineformat.setDashStyle(MsoLineDashStyle.SOLID); | |
// Add another arc shape. | |
com.aspose.cells.ArcShape arc2 = (com.aspose.cells.ArcShape) excelbook.getWorksheets().get(0).getShapes() | |
.addShape(MsoDrawingType.ARC, 9, 2, 0, 0, 130, 130); | |
// Set the placement of the arc. | |
arc2.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the line style. | |
LineFormat lineformat1 = arc2.getLine(); //getLineFormat(); | |
lineformat1.setDashStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat1.setWeight(1); | |
// Set the color of the arc line. | |
lineformat1.setOneColorGradient(Color.getLime(), 1, GradientStyleType.HORIZONTAL, 1);//setForeColor(Color.getBlue()); | |
// Set the dash style of the arc. | |
lineformat1.setDashStyle(MsoLineDashStyle.SOLID); | |
// Save the excel file. | |
excelbook.save(dataDir + "AddingArcControl_out.xls"); |
楕円形コントロールをワークシートに追加する
Aspose.Cells では、ワークシートに楕円形を描くことができます。シンプルで塗りつぶされた楕円形を作成し、コントロールの塗りつぶしの色と境界線の色をフォーマットします。たとえば、楕円の色を指定/変更したり、シェーディングの色を設定したり、形状の太さとスタイルを指定したりできます。
Microsoft エクセルを使う
- 上で描くツールバー、クリックオーバル .
- ドラッグして楕円を描きます。
- 次のいずれかまたは両方を実行します。
- 始点から円を描くように楕円を制限するには、Shift キーを押しながらドラッグします。
- 中心点から楕円を描くには、CTRL キーを押しながらドラッグします。
Aspose.Cells を使用
のシェイプコレクションクラスは、楕円形をワークシートに追加するために使用される addShape という名前のメソッドを提供します。このメソッドは、Oval オブジェクトを返す場合があります。 Oval クラスは、楕円形を表します。いくつかの重要なメンバーがあります。
- setLineFormat メソッドは、楕円形の線フォーマット属性を指定します。
- setPlacement メソッドは、配置タイプ、楕円がワークシートのセルに接続される方法。
- FillFormat プロパティは、図形の塗りつぶし形式のスタイルを指定します。
次の例は、楕円形をワークシートに追加する方法を示しています。この例では、2 つの楕円形を作成します。1 つは塗りつぶされた楕円形で、もう 1 つは単純な円です。コードを実行すると、次の出力が生成されます。
ワークシートに 2 つの楕円形が追加されます
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AddinganOvalControl.class) + "DrawingObjects/"; | |
// Instantiate a new Workbook. | |
Workbook excelbook = new Workbook(); | |
// Add an oval shape. | |
Oval oval1 = (com.aspose.cells.Oval) excelbook.getWorksheets().get(0).getShapes().addShape(MsoDrawingType.OVAL, | |
2, 2, 0, 0, 130, 130); | |
// Set the placement of the oval. | |
oval1.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the fill format. | |
FillFormat fillformat = oval1.getFill();// getFillFormat(); | |
fillformat.setOneColorGradient(Color.getNavy(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the line style. | |
LineFormat lineformat = oval1.getLine();// getLineFormat(); | |
lineformat.setDashStyle(MsoLineStyle.SINGLE); //setStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat.setWeight(1); | |
// Set the color of the oval line. | |
lineformat.setOneColorGradient(Color.getGreen(), 1, GradientStyleType.HORIZONTAL, 1); | |
// Set the dash style of the oval. | |
lineformat.setDashStyle(MsoLineDashStyle.SOLID); | |
// Add another arc shape. | |
Oval oval2 = (com.aspose.cells.Oval) excelbook.getWorksheets().get(0).getShapes().addShape(MsoDrawingType.OVAL, | |
9, 2, 0, 0, 130, 130); | |
// Set the placement of the oval. | |
oval2.setPlacement(PlacementType.FREE_FLOATING); | |
// Set the line style. | |
LineFormat lineformat1 = oval2.getLine(); | |
lineformat.setDashStyle(MsoLineStyle.SINGLE); //setStyle(MsoLineStyle.SINGLE); | |
// Set the line weight. | |
lineformat1.setWeight(1); | |
// Set the color of the oval line. | |
lineformat1.setOneColorGradient(Color.getBlue(),1, GradientStyleType.HORIZONTAL, 1); | |
// Set the dash style of the oval. | |
lineformat1.setDashStyle(MsoLineDashStyle.SOLID); | |
// Save the excel file. | |
excelbook.save(dataDir + "AddinganOvalControl_out.xls"); |