如何添加/插入文本框到工作表

在 Excel 中将文本框添加到工作表

在Excel程序(07及以上版本)中,有两个地方可以插入文本框。一个在“插入形状”中,另一个在“插入”选项顶部菜单的右侧。

方法一:

1

方法二:

2

如何创建

您可以创建带有水平或垂直文本的文本框。

  • 选择相应的选项(水平或垂直)
  • 左键点击页面
  • 按住左键并在页面上拖动一段距离
  • 松开左键

现在你得到一个文本框。

在 Aspose.Cells 中将文本框添加到工作表

当您需要将TextBox批量插入到工作表中时,手动插入的方式显然是一场灾难。如果这让您感到困扰,我想这篇文档可以帮到您。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);

你会得到一个类似于结果文件.在文件中,您将看到以下内容: