テキスト数値データを数値に変換する
Contents
[
Hide
]
テキストとして入力された数値データを数値に変換したい場合があります。 Microsoft Excel では、数字の前にアポストロフィを付けることで、数字をテキストとして入力できます。たとえば、‘12345.その後、Excel はその数値を文字列として扱います。 Aspose.Cells を使用すると、文字列を数値に変換できます。
Aspose.Cells はCells.ConvertStringToNumericValue()すべての文字列またはテキストの数値データを数値に変換するために使用できるメソッド。
次のスクリーンショットは、セル内の文字列番号を示していますA1:A17.文字列番号は左揃えです。
入力ファイル: テキスト文字列として入力された数値 |
---|
![]() |
これらの文字列番号は、次を使用して数値に変換されていますCells.ConvertStringToNumericValue()次のスクリーンショットで。ご覧のとおり、右揃えになりました。
出力ファイル: 文字列は数値に変換されています |
---|
![]() |
C# 文字列数値データを実際の数値に変換するコード
次のサンプル コードは、すべてのワークシートですべての文字列数値データを実際の数値に変換する方法を示しています。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate workbook object with an Excel file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
for (int i = 0; i < workbook.Worksheets.Count; i++) | |
{ | |
workbook.Worksheets[i].Cells.ConvertStringToNumericValue(); | |
} | |
workbook.Save(dataDir + "output_out.xlsx"); |