Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Created Unassigned: InsertData failes if at least one element is null [9411]

$
0
0
Hi,

```
<TestMethod()> Sub WriteNothing()

Dim workBook As New XLWorkbook(XLEventTracking.Disabled)
Dim workSheet As IXLWorksheet = workBook.Worksheets.Add("Sheet 1")

Dim array(3) As Object

array(0) = 1
array(1) = Nothing
array(2) = 2
array(3) = 3

workSheet.Range("A1").FirstCell.InsertData(array)

End Sub
```

workaround

```
public IXLRange InsertData(IEnumerable data) {
if (data != null && data.GetType() != typeof(String)) {
var ro = Address.RowNumber;
var maxCo = 0;
var isDataTable = false;
var isDataReader = false;
foreach (var m in data) {
var co = Address.ColumnNumber;

if (m == null) {
SetValue(m, ro, co);
co++;
}
else if (m.GetType().IsPrimitive || m is string || m is DateTime || m is Decimal) {
SetValue(m, ro, co);
co++;
}
else if (m.GetType().IsArray) { ....
```

regards,
Michael

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>