如何在工作表中添加/插入文本框
Contents
[
Hide
]
在Excel中的工作表中添加文本框
在Excel程序中(07版本及以上),有两个地方可以插入文本框。一个是在“插入图形”中,另一个在“插入”选项的顶部菜单的右侧。
方法一:
方法二:
如何创建
您可以创建水平或垂直文本框。
- 选择相应的选项(水平或垂直)
- 在页面上单击左键
- 按住左键并在页面上拖动一段距离
- 释放左键
现在您可以获得一个文本框。
在Aspose.Cells中的工作表中添加文本框
当您需要批量将文本框插入工作表时,手工插入的方法显然是一场灾难。如果这困扰着您,我认为这份文档会帮助您。【Aspose.Cells】(https://products.aspose.com/cells/)为您提供了一个API,可以轻松地在您的代码中进行批量插入。
以下示例代码创建一个文本框。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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的文件。在该文件中,您将看到以下内容: