特定のシステムカルチャ情報を使用してワークブックをロードする
Contents
[
Hide
]
可能な使用シナリオ
以前は、数値や日付を特定のカルチャ形式で処理するために、スレッド全体のカルチャ情報を変更する必要がありましたが、Aspose.Cells では LoadOptions.CultureInfo プロパティを使用してスレッド全体のカルチャ情報を変更せずに特定のカルチャ情報を使用してワークブックをロードできます。
特定のシステムカルチャ情報を使用してワークブックをロードする
以下のサンプルコードでは、特定のシステムカルチャ情報を使用して日付の処理を行うためにワークブックをロードする方法を示しています。
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 | |
using (var inputStream = new MemoryStream()) | |
{ | |
using (var writer = new StreamWriter(inputStream)) | |
{ | |
writer.WriteLine("<html><head><title>Test Culture</title></head><body><table><tr><td>10-01-2016</td></tr></table></body></html>"); | |
writer.Flush(); | |
var culture = new CultureInfo("en-GB"); | |
culture.NumberFormat.NumberDecimalSeparator = ","; | |
culture.DateTimeFormat.DateSeparator = "-"; | |
culture.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy"; | |
LoadOptions options = new LoadOptions(LoadFormat.Html); | |
options.CultureInfo = culture; | |
using (var workbook = new Workbook(inputStream, options)) | |
{ | |
var cell = workbook.Worksheets[0].Cells["A1"]; | |
Assert.AreEqual(CellValueType.IsDateTime, cell.Type); | |
Assert.AreEqual(new DateTime(2016, 1, 10), cell.DateTimeValue); | |
} | |
} | |
} |
以下のサンプルコードでは、特定のシステムカルチャ情報を使用して数値の処理を行うためにワークブックをロードする方法を示しています。
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 | |
using (var inputStream = new MemoryStream()) | |
{ | |
using (var writer = new StreamWriter(inputStream)) | |
{ | |
writer.WriteLine("<html><head><title>Test Culture</title></head><body><table><tr><td>1234,56</td></tr></table></body></html>"); | |
writer.Flush(); | |
var culture = new CultureInfo("en-GB"); | |
culture.NumberFormat.NumberDecimalSeparator = ","; | |
culture.DateTimeFormat.DateSeparator = "-"; | |
culture.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy"; | |
LoadOptions options = new LoadOptions(LoadFormat.Html); | |
options.CultureInfo = culture; | |
using (var workbook = new Workbook(inputStream, options)) | |
{ | |
var cell = workbook.Worksheets[0].Cells["A1"]; | |
Assert.AreEqual(CellValueType.IsNumeric, cell.Type); | |
Assert.AreEqual(1234.56, cell.DoubleValue); | |
} | |
} | |
} |