How to Extract Text from a Textbox on Excel worksheet in C#

Spire.XLS supports to work with Text Box. We have already shown to you how to add the textbox to an Excel worksheet and set the font and background for the textbox. We may need to extract the value (text) from a Textbox that exists on a spreadsheet to get the abstract and introduce information for the Excel worksheet. This article will demonstrate how to extract text from Excel Textbox in C#. Check the original excel file with the textbox firstly:

How to Extract Text from a Textbox on Excel worksheet in C#

Here comes to the steps of how to get the text from the excel textbox:

Step 1: Create a new instance of workbook and load an Excel file with textbox from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Step 2: Get the worksheet named in "Sheet1" which contains textbox.

Worksheet sheet = workbook.Worksheets["Sheet1"];

Step 3: Get the first textbox.

XlsTextBoxShape shape = sheet.TextBoxes[0] as XlsTextBoxShape;

Step 4: Read the text from the textbox and output it.

Console.WriteLine(shape.Text);
Console.ReadKey();

Effective screenshot:

How to Extract Text from a Textbox on Excel worksheet in C#

Full codes:

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Worksheet sheet = workbook.Worksheets["Sheet1"];
XlsTextBoxShape shape = sheet.TextBoxes[0] as XlsTextBoxShape;

Console.WriteLine(shape.Text);
Console.ReadKey();