Skip to content

Commit 5c887d2

Browse files
authored
Merge pull request #2041 from syncfusion-content/988546-PreserveTypes
988546-Preserve data types while importing DataTable to Excel
2 parents b3dfbf8 + 8d54d38 commit 5c887d2

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Document-Processing/Excel/Excel-Library/NET/Import-Export/Import-to-Excel.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ A complete working example to import data from DataTable to Excel in C# is prese
7575

7676
N> XlsIO imports the data from data table into Excel worksheet based on the data table column type. So, it is suggested to create the data tables with required column types such as number, text or date time before importing the data table to Excel worksheet.
7777

78+
### Preserve Data Types
79+
80+
To preserve data types when importing a DataTable into an Excel worksheet, set the **preserveTypes** parameter of the <a href="https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IWorksheet.html#Syncfusion_XlsIO_IWorksheet_ImportDataTable_System_Data_DataTable_System_Boolean_System_Int32_System_Int32_System_Boolean_">ImportDataTable</a> method to **true**.
81+
82+
{% tabs %}
83+
{% highlight c# tabtitle="C# [Cross-platform]" %}
84+
worksheet.ImportDataTable(table, false, 1, 1, true); // preserveTypes = true
85+
{% endhighlight %}
86+
87+
{% highlight c# tabtitle="C# [Windows-specific]" %}
88+
worksheet.ImportDataTable(table, false, 1, 1, true); // preserveTypes = true
89+
{% endhighlight %}
90+
91+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
92+
worksheet.ImportDataTable(table, False, 1, 1, True) ' preserveTypes = True
93+
{% endhighlight %}
94+
{% endtabs %}
95+
7896
## DataColumn to Excel
7997

8098
The following code example illustrates how to import DataColumn into an Excel using [ImportDataColumn](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IWorksheet.html#Syncfusion_XlsIO_IWorksheet_ImportDataColumn_System_Data_DataColumn_System_Boolean_System_Int32_System_Int32_) method.
@@ -2609,4 +2627,4 @@ Using excelEngine As ExcelEngine = New ExcelEngine()
26092627
workbook.SaveAs("Output.xlsx")
26102628
End Using
26112629
{% endhighlight %}
2612-
{% endtabs %}
2630+
{% endtabs %}

0 commit comments

Comments
 (0)