ワークシートにテキストボックスを追加/挿入する方法
Excel でワークシートにテキストボックスを追加
Excel プログラム(07以降のバージョン)では、テキストボックスを挿入できるのは2か所あります。「挿入」の下に「図形プレースメント」と「挿入」オプションの上に右側にもう一箇所あります。
方法1:
方法2:
作成方法
水平または垂直のテキストボックスを作成できます。
- 対応するオプション(水平または垂直)を選択します。
- ページ上で左クリックします。
- 左ボタンを押したまま、ページ上で距離をドラッグします。
- 左ボタンを離します。
これでテキストボックスができます。
Aspose.Cells でワークシートにテキストボックスを追加
ワークシートに大量のテキストボックスを挿入する必要がある場合、手動の挿入方法は明らかに非効率です。これに悩んでいる場合、このドキュメントが役立つと思います。Aspose.Cells はあなたのコードで簡単に大量挿入を行うための API を提供します。
次のサンプルコードはテキストボックスを作成します。
// 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 = ""; | |
// Create directory if it is not already present. | |
File file = new File(dataDir); | |
if(!file.exists()) | |
file.mkdir(); | |
// Open an Excel file. | |
//Workbook workbook = new Workbook(dataDir+ "Book_SourceData.xlsx");//If you want to insert a text box in an existing file, use this code. | |
// Create an object of the Workbook class | |
Workbook workbook = new Workbook(); | |
// Access first worksheet from the collection | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Add the TextBox to the worksheet | |
sheet.getTextBoxes().add(6, 10, 100, 200); | |
//Save.You can check your text box in this way. | |
workbook.save("result.xlsx", SaveFormat.XLSX); |
result file に類似したファイルが得られます。ファイルでは、以下が見られます: