From ee4b7473cd29c2e68037a384d7417ad3dbe253e8 Mon Sep 17 00:00:00 2001 From: santiprajaSF4793 Date: Wed, 21 Jan 2026 21:56:47 +0530 Subject: [PATCH 1/3] 988674-DatetimeUG --- Document-Processing-toc.html | 3 + ...te-values-to-datetime-in-excel-workbook.md | 149 ++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 9c0aa43dc..8f251fab2 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6299,6 +6299,9 @@
  • How to retrieve the name of the chart in an Excel worksheet?
  • +
  • + How to convert text‑formatted date values to DateTime in an Excel workbook? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md new file mode 100644 index 000000000..2ec1dfe2c --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md @@ -0,0 +1,149 @@ +--- +title: Convert text-formatted date values to DateTime in Excel workbook | Syncfusion +description: Code example to convert text-formatted date values to DateTime in Excel workbook using Syncfusion .NET Excel library (XlsIO). +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to convert text‑formatted date values to DateTime in an Excel workbook? + +The following code examples demonstrate converting text-formatted date values to DateTime in Excel workbook using C# (Cross-platform and Windows-specific) and VB.NET. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/DateTime/.NET/TextToDateTimeConverter/TextToDateTimeConverter/Program.cs,180" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Open the input workbook + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); + + //Access the first worksheet + IWorksheet worksheet = workbook.Worksheets[0]; + + //Get the used range to iterate through populated cells + IRange used = worksheet.UsedRange; + + //Set culture and parsing styles for interpreting text dates + CultureInfo culture = new CultureInfo("en-IN"); + DateTimeStyles styles = DateTimeStyles.None; + + //Iterate through the used range and convert text-formatted dates to DateTime + for (int row = used.Row; row <= used.LastRow; row++) + { + for (int col = used.Column; col <= used.LastColumn; col++) + { + IRange cell = worksheet[row, col]; + DateTime date; + + //Log if the cell already contains a true DateTime + if (cell.HasDateTime) + { + Console.WriteLine(cell.DateTime); + } + //Try parsing text using the specified culture and assign DateTime back to the cell + else if (DateTime.TryParse(cell.Value, culture, styles, out date)) + { + cell.DateTime = date; + } + } + } + + //Saving the workbook + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + //Open the input workbook + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); + + //Access the first worksheet + IWorksheet worksheet = workbook.Worksheets[0]; + + //Get the used range to iterate through populated cells + IRange used = worksheet.UsedRange; + + //Set culture and parsing styles for interpreting text dates + CultureInfo culture = new CultureInfo("en-IN"); + DateTimeStyles styles = DateTimeStyles.None; + + //Iterate through the used range and convert text-formatted dates to DateTime + for (int row = used.Row; row <= used.LastRow; row++) + { + for (int col = used.Column; col <= used.LastColumn; col++) + { + IRange cell = worksheet[row, col]; + DateTime date; + + //Log if the cell already contains a true DateTime + if (cell.HasDateTime) + { + Console.WriteLine(cell.DateTime); + } + //Try parsing text using the specified culture and assign DateTime back to the cell + else if (DateTime.TryParse(cell.Value, culture, styles, out date)) + { + cell.DateTime = date; + } + } + } + + //Saving the workbook + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + 'Open the input workbook + Dim workbook As IWorkbook = application.Workbooks.Open("Input.xlsx") + + 'Access the first worksheet + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + 'Get the used range to iterate through populated cells + Dim used As IRange = worksheet.UsedRange + + 'Set culture and parsing styles for interpreting text dates + Dim culture As New CultureInfo("en-IN") + Dim styles As DateTimeStyles = DateTimeStyles.None + + 'Iterate through the used range and convert text-formatted dates to DateTime + For row As Integer = used.Row To used.LastRow + For col As Integer = used.Column To used.LastColumn + + Dim cell As IRange = worksheet(row, col) + Dim parsedDate As DateTime + + 'Log if the cell already contains a true DateTime + If cell.HasDateTime Then + Console.WriteLine(cell.DateTime) + + 'Try parsing text using the specified culture and assign DateTime back to the cell + ElseIf DateTime.TryParse(cell.Value, culture, styles, parsedDate) Then + cell.DateTime = parsedDate + End If + + Next + Next + + 'Saving the workbook + workbook.SaveAs("Output.xlsx") + +End Using +{% endhighlight %} +{% endtabs %} + +A complete working example in C# is present on this GitHub page. \ No newline at end of file From 236487c6e698e26899c82afbf0734313e919f361 Mon Sep 17 00:00:00 2001 From: santiprajaSF4793 Date: Wed, 21 Jan 2026 22:30:54 +0530 Subject: [PATCH 2/3] 988674-DatetimeUG --- Document-Processing-toc.html | 2 +- ...ed-date-values-to-datetime-in-excel-workbook.md | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 8f251fab2..3b8dc7f35 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6300,7 +6300,7 @@ How to retrieve the name of the chart in an Excel worksheet?
  • - How to convert text‑formatted date values to DateTime in an Excel workbook? + How to convert text formatted date values to DateTime in an Excel workbook?
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md index 2ec1dfe2c..cba75ed75 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md @@ -1,14 +1,14 @@ --- -title: Convert text-formatted date values to DateTime in Excel workbook | Syncfusion -description: Code example to convert text-formatted date values to DateTime in Excel workbook using Syncfusion .NET Excel library (XlsIO). +title: Convert text formatted date values to DateTime in Excel workbook | Syncfusion +description: Code example to convert text formatted date values to DateTime in Excel workbook using Syncfusion .NET Excel library (XlsIO). platform: document-processing control: XlsIO documentation: UG --- -# How to convert text‑formatted date values to DateTime in an Excel workbook? +# How to convert text formatted date values to DateTime in an Excel workbook? -The following code examples demonstrate converting text-formatted date values to DateTime in Excel workbook using C# (Cross-platform and Windows-specific) and VB.NET. +The following code examples demonstrate converting text formatted date values to DateTime in Excel workbook using C# (Cross-platform and Windows-specific) and VB.NET. {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/DateTime/.NET/TextToDateTimeConverter/TextToDateTimeConverter/Program.cs,180" %} @@ -30,7 +30,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) CultureInfo culture = new CultureInfo("en-IN"); DateTimeStyles styles = DateTimeStyles.None; - //Iterate through the used range and convert text-formatted dates to DateTime + //Iterate through the used range and convert text formatted dates to DateTime for (int row = used.Row; row <= used.LastRow; row++) { for (int col = used.Column; col <= used.LastColumn; col++) @@ -75,7 +75,7 @@ using (ExcelEngine excelEngine = new ExcelEngine()) CultureInfo culture = new CultureInfo("en-IN"); DateTimeStyles styles = DateTimeStyles.None; - //Iterate through the used range and convert text-formatted dates to DateTime + //Iterate through the used range and convert text formatted dates to DateTime for (int row = used.Row; row <= used.LastRow; row++) { for (int col = used.Column; col <= used.LastColumn; col++) @@ -120,7 +120,7 @@ Using excelEngine As New ExcelEngine() Dim culture As New CultureInfo("en-IN") Dim styles As DateTimeStyles = DateTimeStyles.None - 'Iterate through the used range and convert text-formatted dates to DateTime + 'Iterate through the used range and convert text formatted dates to DateTime For row As Integer = used.Row To used.LastRow For col As Integer = used.Column To used.LastColumn From 846ea6fdcec0391b168206cc8c097d9024d6b033 Mon Sep 17 00:00:00 2001 From: santiprajaSF4793 Date: Wed, 21 Jan 2026 22:44:22 +0530 Subject: [PATCH 3/3] 988674-DatetimeUG --- Document-Processing-toc.html | 2 +- ...onvert-text-formatted-date-values-to-datetime-in-excel.md} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename Document-Processing/Excel/Excel-Library/NET/faqs/{how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md => how-to-convert-text-formatted-date-values-to-datetime-in-excel.md} (98%) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 3b8dc7f35..3c5735fa2 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6300,7 +6300,7 @@ How to retrieve the name of the chart in an Excel worksheet?
  • - How to convert text formatted date values to DateTime in an Excel workbook? + How to convert text formatted date values to DateTime in an Excel?
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel.md similarity index 98% rename from Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md rename to Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel.md index cba75ed75..e0f7ab941 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel-workbook.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-convert-text-formatted-date-values-to-datetime-in-excel.md @@ -1,12 +1,12 @@ --- -title: Convert text formatted date values to DateTime in Excel workbook | Syncfusion +title: Convert text formatted date values to DateTime in Excel | Syncfusion description: Code example to convert text formatted date values to DateTime in Excel workbook using Syncfusion .NET Excel library (XlsIO). platform: document-processing control: XlsIO documentation: UG --- -# How to convert text formatted date values to DateTime in an Excel workbook? +# How to convert text formatted date values to DateTime in an Excel? The following code examples demonstrate converting text formatted date values to DateTime in Excel workbook using C# (Cross-platform and Windows-specific) and VB.NET.