# GrapeCity.Documents.Excel.IRange.ImportData

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="GrapeCity_Documents_Excel_IRange_ImportData_" data-uid="GrapeCity.Documents.Excel.IRange.ImportData*">ImportData Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="GrapeCity_Documents_Excel_IRange_ImportData_" data-uid="GrapeCity.Documents.Excel.IRange.ImportData*"></a>
<h4 id="GrapeCity_Documents_Excel_IRange_ImportData_System_Collections_IEnumerable_GrapeCity_Documents_Excel_DataImportOptions_" data-uid="GrapeCity.Documents.Excel.IRange.ImportData(System.Collections.IEnumerable,GrapeCity.Documents.Excel.DataImportOptions)">ImportData(IEnumerable, DataImportOptions)</h4>
<div class="markdown level1 summary"><p>Imports data from a data source (up to 2D) to the range.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">DataImportResult ImportData(IEnumerable items, DataImportOptions options = null)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Function ImportData(items As IEnumerable, Optional options As DataImportOptions = Nothing) As DataImportResult</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.ienumerable">IEnumerable</a></td>
      <td><span class="parametername">items</span></td>
      <td><p>The items to import. The element type can be: <br><ul><li>
Primitive types: <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.sbyte">sbyte</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int16">short</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint16">ushort</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint32">uint</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int64">long</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint64">ulong</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.double">double</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.decimal">decimal</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.datetime">DateTime</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.timespan">TimeSpan</a> or <a class="xref" href="GrapeCity.Documents.Excel.CalcError.html">CalcError</a>.
</li><li>
Nullable primitives: <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a> or <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.nullable-1">Nullable&lt;T&gt;</a> where T is a primitive type.
</li><li>
Custom objects: objects that have properties to be mapped to cell values.
</li><li><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary-2">IReadOnlyDictionary&lt;TKey, TValue&gt;</a> or 
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2">IDictionary&lt;TKey, TValue&gt;</a> or 
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.idictionary">IDictionary</a> where the key is <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a>: 
It will be treated as collection of property names and values. 
</li><li><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.data.datarow">DataRow</a> or <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.data.datarowview">DataRowView</a>.
</li></ul>
The collection type can be: <br><ul><li>
Flat (non-jagged, 1D in total) <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.ienumerable">IEnumerable</a>. For example, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.data.dataview">DataView</a>.
</li><li>
Jagged (2D in total) <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.ienumerable">IEnumerable</a> or <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable&lt;T&gt;</a> where the element type of inner collection is primitive or nullable primitive.
</li><li>
2D array where element type is primitive or nullable primitive.
</li></ul>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.DataImportOptions.html">DataImportOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>The import options.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.DataImportResult.html">DataImportResult</a></td>
      <td></td>
    </tr>
  </tbody>
</table>
<h5 id="GrapeCity_Documents_Excel_IRange_ImportData_System_Collections_IEnumerable_GrapeCity_Documents_Excel_DataImportOptions__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>If the item collection is a list of primitive types,
the orientation is determined by the shape of range.
If the row count of the range is greater than column count,
we import the collection vertically.
Otherwise, we import the collection horizontally.</p>
</div>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidcastexception">InvalidCastException</a></td>
      <td><p>The data type of a column is inconsistent. Use <a class="xref" href="GrapeCity.Documents.Excel.DataImportOptions.ItemTypeProvider.html#GrapeCity_Documents_Excel_DataImportOptions_ItemTypeProvider">ItemTypeProvider</a> to fix it.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></td>
      <td><p>An item is of an unsupported type or <code class="paramref">options</code> contains incorrect information.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.notsupportedexception">NotSupportedException</a></td>
      <td><p>It's typically thrown when AOT compatibility issues occur at runtime.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="GrapeCity_Documents_Excel_IRange_ImportData_" data-uid="GrapeCity.Documents.Excel.IRange.ImportData*"></a>
<h4 id="GrapeCity_Documents_Excel_IRange_ImportData__1_System_Collections_Generic_IEnumerable___0__GrapeCity_Documents_Excel_DataImportOptions_" data-uid="GrapeCity.Documents.Excel.IRange.ImportData``1(System.Collections.Generic.IEnumerable{``0},GrapeCity.Documents.Excel.DataImportOptions)">ImportData&lt;T&gt;(IEnumerable&lt;T&gt;, DataImportOptions)</h4>
<div class="markdown level1 summary"><p>Imports data from a data source (up to 2D) to the range.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">DataImportResult ImportData&lt;T&gt;(IEnumerable&lt;T&gt; items, DataImportOptions options = null)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Function ImportData(Of T)(items As IEnumerable(Of T), Optional options As DataImportOptions = Nothing) As DataImportResult</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable</a>&lt;T&gt;</td>
      <td><span class="parametername">items</span></td>
      <td><p>The items to import. The element type can be: <br><ul><li>
Primitive types: <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.sbyte">sbyte</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int16">short</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint16">ushort</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint32">uint</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int64">long</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint64">ulong</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.double">double</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.decimal">decimal</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.datetime">DateTime</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.timespan">TimeSpan</a> or <a class="xref" href="GrapeCity.Documents.Excel.CalcError.html">CalcError</a>.
</li><li>
Nullable primitives: <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a> or <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.nullable-1">Nullable&lt;T&gt;</a> where T is a primitive type.
</li><li>
Custom objects: objects that have properties to be mapped to cell values.
</li><li><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary-2">IReadOnlyDictionary&lt;TKey, TValue&gt;</a> or 
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2">IDictionary&lt;TKey, TValue&gt;</a> or 
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.idictionary">IDictionary</a> where the key is <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a>: 
It will be treated as collection of property names and values. 
</li><li><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.data.datarow">DataRow</a> or <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.data.datarowview">DataRowView</a>.
</li></ul>
The collection type can be: <br><ul><li>
Flat (non-jagged, 1D in total) <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable&lt;T&gt;</a>.
</li><li>
Jagged (2D in total) <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1">IEnumerable&lt;T&gt;</a> where the element type of inner collection is primitive or nullable primitive.
</li><li>
2D array where element type is primitive or nullable primitive.
</li></ul>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.DataImportOptions.html">DataImportOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>The import options.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.DataImportResult.html">DataImportResult</a></td>
      <td></td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">T</span></td>
      <td></td>
    </tr>
  </tbody>
</table>
<h5 id="GrapeCity_Documents_Excel_IRange_ImportData__1_System_Collections_Generic_IEnumerable___0__GrapeCity_Documents_Excel_DataImportOptions__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>If the item collection is a list of primitive types,
the orientation is determined by the shape of range.
If the row count of the range is greater than column count,
we import the collection vertically.
Otherwise, we import the collection horizontally.</p>
</div>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidcastexception">InvalidCastException</a></td>
      <td><p>The data type of a column is inconsistent. Check whether the implementation of <a class="xref" href="GrapeCity.Documents.Excel.DataImportOptions.ItemTypeProvider.html#GrapeCity_Documents_Excel_DataImportOptions_ItemTypeProvider">ItemTypeProvider</a> is correct.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></td>
      <td><p>An item is of an unsupported type or <code class="paramref">options</code> contains incorrect information.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.notsupportedexception">NotSupportedException</a></td>
      <td><p>It's typically thrown when AOT compatibility issues occur at runtime.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="GrapeCity_Documents_Excel_IRange_ImportData_" data-uid="GrapeCity.Documents.Excel.IRange.ImportData*"></a>
<h4 id="GrapeCity_Documents_Excel_IRange_ImportData_System_Data_DataTable_GrapeCity_Documents_Excel_DataImportOptions_" data-uid="GrapeCity.Documents.Excel.IRange.ImportData(System.Data.DataTable,GrapeCity.Documents.Excel.DataImportOptions)">ImportData(DataTable, DataImportOptions)</h4>
<div class="markdown level1 summary"><p>Imports data from a table to the range.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">DataImportResult ImportData(DataTable table, DataImportOptions options = null)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Function ImportData(table As DataTable, Optional options As DataImportOptions = Nothing) As DataImportResult</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.data.datatable">DataTable</a></td>
      <td><span class="parametername">table</span></td>
      <td><p>The table to import. The column type can be: <br><ul><li>
Primitive types: <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.sbyte">sbyte</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int16">short</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint16">ushort</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint32">uint</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int64">long</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.uint64">ulong</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.single">float</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.double">double</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.decimal">decimal</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.datetime">DateTime</a>, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.timespan">TimeSpan</a> or <a class="xref" href="GrapeCity.Documents.Excel.CalcError.html">CalcError</a>.
</li><li>
Nullable primitives: <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a> or <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.nullable-1">Nullable&lt;T&gt;</a> where T is a primitive type.
</li></ul>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.DataImportOptions.html">DataImportOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>The import options.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Excel.DataImportResult.html">DataImportResult</a></td>
      <td></td>
    </tr>
  </tbody>
</table>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Condition</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.invalidcastexception">InvalidCastException</a></td>
      <td><p>The data type of a column is inconsistent.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentexception">ArgumentException</a></td>
      <td><p><code class="paramref">options</code> contains incorrect information.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.notsupportedexception">NotSupportedException</a></td>
      <td><p>It's typically thrown when AOT compatibility issues occur at runtime.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
