Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

Created Unassigned: Excel Pivot Table SourceData Range >65536 Crashes [21086]

$
0
0
Hi Guys.

Running 1.6 and am trying to create a Pivot Table in Excel. I can get it to generate fine as long as the SourceData range does not go over 65536. If I go to 65537 I get:

```
{"Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"}
```

I assume there is a ushort variable limit to blame here? Here is the code that causes the problem (abbreviated to save space):

```
var workbook = ExcelApplication.ActiveWorkbook;
if (workbook == null)
return;

var DataWorksheet = (Worksheet)workbook.Worksheets.FirstOrDefault(ws => ((Worksheet)ws).Name == "Data");
if (DataWorksheet == null)
return;

var pivotsheet = workbook.Worksheets.Add() as Worksheet;
if (pivotsheet == null)
return;

// THE EVENTUAL PROBLEM WHEN > 65536
var usedrange = DataWorksheet.Range("A1:U65537");

//THIS LINE WILL CAUSE THE EXCEPTION WHEN usedrange IS > 65536
var pivotcache = workbook.PivotCaches().Add(XlPivotTableSourceType.xlDatabase, usedrange);

var pivottables = pivotsheet.PivotTables() as PivotTables;

if (pivottables != null)
{
var pivottable = pivottables.Add(pivotcache, pivotsheet.Range("A1"), "PivotTable1");
pivottable.InGridDropZones = false;
}
```

Thanks
Ernie

Viewing all articles
Browse latest Browse all 1741

Trending Articles



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