//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); var sheet = workbook.ActiveSheet; sheet.Range["A1"].Value = "Culture \\ Format"; var formats = new[] { "[$-x-sysdate]dddd, mmmm dd, yyyy", "[$-x-systime]h:mm:ss AM/PM" }; var cultures = new[] { "en-US", "zh-CN", "en-GB", "ja-JP", "en-AU" }; // Add headers for (var formatId = 0; formatId < formats.Length; formatId++) { sheet.Range[0, formatId + 1].Value = formats[formatId]; } for (var cultureId = 0; cultureId < cultures.Length; cultureId++) { sheet.Range[cultureId + 1, 0].Value = cultures[cultureId]; } // Format date cells with different cultures for (var cultureId = 0; cultureId < cultures.Length; cultureId++) { workbook.Culture = CultureInfo.GetCultureInfo(cultures[cultureId]); for (var formatId = 0; formatId < formats.Length; formatId++) { var cell = sheet.Range[cultureId + 1, formatId + 1]; cell.Value = 43245.5922; cell.NumberFormat = formats[formatId]; cell.Value = "'" + cell.Text; } } // Arrange sheet.Range["A:F"].EntireColumn.AutoFit(); // Save to an excel file workbook.Save("SystemDateAndTimeFormat.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim sheet = workbook.ActiveSheet sheet.Range!A1.Value = "Culture \ Format" Dim formats = {"[$-x-sysdate]dddd, mmmm dd, yyyy", "[$-x-systime]h:mm:ss AM/PM"} Dim cultures = {"en-US", "zh-CN", "en-GB", "ja-JP", "en-AU"} ' Add headers For formatId = 0 To formats.Length - 1 sheet.Range(0, formatId + 1).Value = formats(formatId) Next For cultureId = 0 To cultures.Length - 1 sheet.Range(cultureId + 1, 0).Value = cultures(cultureId) Next ' Format date cells with different cultures For cultureId = 0 To cultures.Length - 1 workbook.Culture = CultureInfo.GetCultureInfo(cultures(cultureId)) For formatId = 0 To formats.Length - 1 Dim cell = sheet.Range(cultureId + 1, formatId + 1) cell.Value = 43245.5922 cell.NumberFormat = formats(formatId) cell.Value = "'" & cell.Text Next Next ' Arrange sheet.Range("A:F").EntireColumn.AutoFit() ' save to an excel file workbook.Save("SystemDateAndTimeFormat.xlsx")