Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Sometimes, you want to convert numeric data entered as text to numbers. You can enter numbers as text in Microsoft Excel by putting an apostrophe before a number, for example ‘12345. Excel then treats the number as a string. Aspose.Cells allows you to convert strings to numbers.
You can convert numbers stored as text to numbers by following a few simple steps.




Aspose.Cells provides the Cells.ConvertStringToNumericValue() method which can be used to convert all string or text numeric data into numbers.
The following screenshot shows string numbers in cells A1:A17. String numbers are aligned to the left.

These string numbers have been converted to numbers using Cells.ConvertStringToNumericValue() in the following screenshot. As you can see, they are now right-aligned.

The following sample code illustrates how to convert all string numeric data to actual numbers in all worksheets.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate workbook object with an Excel file
U16String inputFilePath = srcDir + u"SampleBook.xlsx";
Workbook workbook(inputFilePath);
// Iterate through all worksheets and convert string values to numeric
for (int32_t i = 0; i < workbook.GetWorksheets().GetCount(); i++)
{
workbook.GetWorksheets().Get(i).GetCells().ConvertStringToNumericValue();
}
// Save the Excel file
U16String outputFilePath = outDir + u"output_out.xlsx";
workbook.Save(outputFilePath);
std::cout << "Conversion completed successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.