Skip to content

Commit 318d8b0

Browse files
988546-PreserveTypes
1 parent 9d1272e commit 318d8b0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
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 and prevent Excel's automatic type conversions, 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.

0 commit comments

Comments
 (0)