Convert Text to Number in Excel using C#

Converting text to numbers in Excel is a common requirement. Many users encounter numbers stored as text, which can lead to calculation errors. This issue affects finance, data analysis, and reporting. Converting these text entries into actual numbers is crucial for accurate data manipulation. In this blog post, we will explore how to convert numbers stored as text to numbers in Excel using C#.

This article covers the following topics:

C# Excel Library to Convert Text to Numbers

Aspose.Cells for .NET is a powerful library that simplifies the process of converting numbers stored as text to numbers in Excel. It provides a straightforward API for developers to manipulate Excel files programmatically. With Aspose.Cells, you can easily read, write, and convert Excel data without needing Microsoft Excel installed. This library is ideal for automating Excel tasks, including converting text to numbers.

To get started with Aspose.Cells for .NET, you can download it from the releases section. Use the following command to install the library via NuGet Package Manager:

PM> Install-Package Aspose.Cells

Convert Numbers Stored as Text to Numbers in Excel Worksheet

Follow these steps to convert numbers stored as text to numbers in an Excel worksheet:

  1. Load the Excel file using the Workbook class.
  2. Access the specific worksheet from the Worksheets collection.
  3. Convert the text to numbers using the ConvertStringToNumericValue() method.
  4. Finally, save the modified workbook using the Save() method.

The following C# code snippet demonstrates these steps:

convert-numbers-stored-as-text-to-numbers

Sample input worksheet.

Output

convert-numbers-stored-as-text-to-numbers

Output.

Convert Text to Numbers in Entire Workbook

Follow these steps to convert numbers stored as text to numbers in an entire Excel workbook:

  1. Load the Excel file using the Workbook class.
  2. Loop through all the worksheets in the Worksheets collection.
  3. For each worksheet, call the ConvertStringToNumericValue() method.
  4. Finally, save the file using the Save() method.

The following code sample shows how to convert numbers stored as text to numbers in all Excel worksheets.

Get a Free License

If you are interested in exploring Aspose products, we invite you to obtain a free temporary license. Visit the license page to get started. It’s easy and allows you to test the full capabilities of Aspose.Cells for .NET.

Convert Excel Text to Number: Free Resources

In addition to converting Excel text to numbers, we encourage you to check out additional resources that can further enhance your understanding and skills with Aspose.Cells for .NET. These resources can provide deeper insights and practical examples.

Conclusion

In this blog post, we explored how to convert text to number in Excel using C# with Aspose.Cells for .NET. This library simplifies the process and offers powerful features for Excel manipulation. We encourage you to explore more about Aspose.Cells for .NET to enhance your Excel automation tasks.

If you have any questions or need further assistance, please feel free to reach out at our free support forum.

See Also