From fa2134db8351e90b0b388ba42e15862a28e773c9 Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Thu, 18 Dec 2025 18:46:33 +0530 Subject: [PATCH 1/4] October second sprint missing PRs. --- Document-Processing-toc.html | 6 + .../NET/faqs/how-to-get-the-column-color.md | 58 ++++++++ ...ding-zeros-when-importing-data-to-excel.md | 140 ++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-get-the-column-color.md create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 9e50c239e..90976da6b 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6088,6 +6088,12 @@
  • How to set the first item in a list as the default value in an Excel?
  • +
  • + How to get the column color when column cells have different colors? +
  • +
  • + How to preserve leading zeros when importing DataTable to Excel? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-get-the-column-color.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-get-the-column-color.md new file mode 100644 index 000000000..eab747f10 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-get-the-column-color.md @@ -0,0 +1,58 @@ +--- +title: How to get the column color | Syncfusion. +description: This page explains how to get the styled column color when column cells have different colors in an Excel document using Syncfusion .NET Excel library (XlsIO). +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to get the column color when column cells have different colors? + +According to Microsoft Excel behavior, when a column's cells have different fill colors, the column color property returns an empty value. Syncfusion XlsIO mirrors this behavior, as Excel doesn't set a unified column color in such cases. This can lead to issues when trying to retrieve color using column cell style properties. +The following code example illustrates how to get the column color when column cells have different colors in an Excel document. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open("Column styles.xlsx", ExcelOpenType.Automatic); + + IWorksheet worksheet = workbook.Worksheets[0]; + + ExtendedFormatImpl format = (workbook as WorkbookImpl).InnerExtFormats[(worksheet["A1"] as RangeImpl).ExtendedFormatIndex]; + Color color = format.Color; +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open("Column styles.xlsx", ExcelOpenType.Automatic); + + IWorksheet worksheet = workbook.Worksheets[0]; + + ExtendedFormatImpl format = (workbook as WorkbookImpl).InnerExtFormats[(worksheet["A1"] as RangeImpl).ExtendedFormatIndex]; + Color color = format.Color; +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim workbook As IWorkbook = application.Workbooks.Open("Column styles.xlsx", ExcelOpenType.Automatic) + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + Dim format As ExtendedFormatImpl = DirectCast(workbook, WorkbookImpl).InnerExtFormats(DirectCast(worksheet("A1"), RangeImpl).ExtendedFormatIndex) + Dim color As Color = format.Color + +End Using +{% endhighlight %} +{% endtabs %} \ No newline at end of file diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md new file mode 100644 index 000000000..9430152db --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md @@ -0,0 +1,140 @@ +--- +title: Preserve leading zeros when importing data to Excel | Syncfusion +description: Discover how to keep leading zeros in text when importing a DataTable to Excel using Syncfusion .NET Excel library. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to preserve leading zeros when importing DataTable to Excel? + +Excel often treats numeric-looking text as numbers, removing leading zeros. The same behavior is followed when importing DataTable to Excel by the Syncfusion .NET Excel (XlsIO) library. The leading zeros can be preserved by providing the parameter "PreserveDataTypes" in the ImportDataTable method as "True" when importing the data. + +The following code snippet shows how to use the PreserveDataTypes option in XlsIO. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} + +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + #region Import from Data Table + //Initialize the DataTable + DataTable table = SampleDataTable(); + //Set the final parameter (preserveTypes) to true to preserve the data types. + worksheet.ImportDataTable(table, true, 1, 1, true); + #endregion + + #region Save + //Saving the workbook + workbook.SaveAs(Path.GetFullPath("Output/ImportDataTable.xlsx")); + #endregion +} +static DataTable SampleDataTable() +{ + //Create a DataTable with four columns + DataTable table = new DataTable(); + table.Columns.Add("Dosage", typeof(int)); + table.Columns.Add("Drug", typeof(string)); + table.Columns.Add("Patient", typeof(string)); + table.Columns.Add("Date", typeof(DateTime)); + + //Add five DataRows + table.Rows.Add(25, "032132", "David", DateTime.Now); + table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); + table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); + table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); + table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); + + return table; +} + +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} + +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Excel2016; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Initialize the DataTable + DataTable table = SampleDataTable(); + + //Set the final parameter (preserveTypes) to true to preserve the data types. + worksheet.ImportDataTable(table, true, 1, 1, true); + + workbook.SaveAs("ImportFromDT.xlsx"); +} +private static DataTable SampleDataTable() +{ + //Create a DataTable with four columns + DataTable table = new DataTable(); + table.Columns.Add("Dosage", typeof(int)); + table.Columns.Add("Drug", typeof(string)); + table.Columns.Add("Patient", typeof(string)); + table.Columns.Add("Date", typeof(DateTime)); + + //Add five DataRows + table.Rows.Add(25, "032132", "David", DateTime.Now); + table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); + table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); + table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); + table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); + + return table; +} + +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + +Using excelEngine As ExcelEngine = New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Excel2016 + Dim workbook As IWorkbook = application.Workbooks.Create(1) + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + 'Initialize the DataTable + Dim table As DataTable = sampleDataTable() + 'Set the final parameter (preserveTypes) to true to preserve the data types. + worksheet.ImportDataTable(table, True, 1, 1, True) + + workbook.SaveAs("ImportFromDT.xlsx") +End Using +Private Function SampleDataTable() As DataTable + ' Create a DataTable with four columns + Dim table As New DataTable() + table.Columns.Add("Dosage", GetType(Integer)) + table.Columns.Add("Drug", GetType(String)) + table.Columns.Add("Patient", GetType(String)) + table.Columns.Add("Date", GetType(Date)) + + ' Add five DataRows + table.Rows.Add(25, "032132", "David", DateTime.Now) + table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now) + table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now) + table.Rows.Add(21, "Combivent", "Janet", DateTime.Now) + table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now) + Return table +End Function + +{% endhighlight %} +{% endtabs %} + +## See Also + +* [How to import data table with its data type using template markers?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-import-data-table-with-its-data-type-using-template-markers) +* [How to import data from DataTable?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datatable) +* [How to import data from DataColumn?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datacolumn) +* [How to import data from DataView?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-dataview) +* [How to export data from worksheet to DataTable?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datatable) +* [What are Import Data Options?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-options) +* [How to bind from DataTable?](https://help.syncfusion.com/file-formats/xlsio/working-with-template-markers#bind-from-datatable) +* [How to bind from Nested Collection Objects with import data and group options?](https://help.syncfusion.com/file-formats/xlsio/working-with-template-markers#bind-from-nested-collection-objects-with-import-data-and-group-options) From 47758616429edcaab5f6901667c18c461158afb4 Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Thu, 18 Dec 2025 19:03:05 +0530 Subject: [PATCH 2/4] Oct2sprint --- ...o-preserve-leading-zeros-when-importing-data-to-excel.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md index 9430152db..758bbe91b 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md @@ -131,10 +131,6 @@ End Function ## See Also * [How to import data table with its data type using template markers?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-import-data-table-with-its-data-type-using-template-markers) -* [How to import data from DataTable?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datatable) -* [How to import data from DataColumn?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datacolumn) -* [How to import data from DataView?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-dataview) -* [How to export data from worksheet to DataTable?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datatable) -* [What are Import Data Options?](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-options) +* [Import to Excel Document](https://help.syncfusion.com/document-processing/excel/excel-library/net/import-export/import-to-excel) * [How to bind from DataTable?](https://help.syncfusion.com/file-formats/xlsio/working-with-template-markers#bind-from-datatable) * [How to bind from Nested Collection Objects with import data and group options?](https://help.syncfusion.com/file-formats/xlsio/working-with-template-markers#bind-from-nested-collection-objects-with-import-data-and-group-options) From fad75da15ae5866a19437280726150e9b38b4ff4 Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Thu, 18 Dec 2025 19:11:29 +0530 Subject: [PATCH 3/4] Oct2sprint --- Document-Processing-toc.html | 6 ------ ...o-preserve-leading-zeros-when-importing-data-to-excel.md | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 90976da6b..9e50c239e 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6088,12 +6088,6 @@
  • How to set the first item in a list as the default value in an Excel?
  • -
  • - How to get the column color when column cells have different colors? -
  • -
  • - How to preserve leading zeros when importing DataTable to Excel? -
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md index 758bbe91b..788d85bd1 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-preserve-leading-zeros-when-importing-data-to-excel.md @@ -131,6 +131,4 @@ End Function ## See Also * [How to import data table with its data type using template markers?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-import-data-table-with-its-data-type-using-template-markers) -* [Import to Excel Document](https://help.syncfusion.com/document-processing/excel/excel-library/net/import-export/import-to-excel) -* [How to bind from DataTable?](https://help.syncfusion.com/file-formats/xlsio/working-with-template-markers#bind-from-datatable) -* [How to bind from Nested Collection Objects with import data and group options?](https://help.syncfusion.com/file-formats/xlsio/working-with-template-markers#bind-from-nested-collection-objects-with-import-data-and-group-options) +* [Import to Excel Document](https://help.syncfusion.com/document-processing/excel/excel-library/net/import-export/import-to-excel) \ No newline at end of file From 298464776c13578e61dca64b3da7c487dc02a80d Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Thu, 18 Dec 2025 19:21:51 +0530 Subject: [PATCH 4/4] Oct2sprint --- Document-Processing-toc.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 6fd33efca..103e3b977 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6091,6 +6091,12 @@
  • How to perform a clean installation of a NuGet package from a local source?
  • +
  • + How to get the column color when column cells have different colors? +
  • +
  • + How to preserve leading zeros when importing DataTable to Excel? +