I came across another exception (Object reference not set to an instance of an object) while converting a chart to image.
Here is the sample’s code:
var loadOptions = new LoadOptions(LoadFormat.Xlsx);
var dataOption = new LoadDataOption();
dataOption.ImportFormula = true;
loadOptions.LoadDataOnly = false;
loadOptions.LoadDataOptions = dataOption;
Workbook wb = new Workbook(@“C:\Users.…\Survey.xlsx”, loadOptions);
<span style="color:blue;">var</span> sheet = wb.Worksheets[0];
<span style="color:blue;">var</span> chart = sheet.Charts[0]; <pre style="font-family: Consolas; background-position: initial initial; background-repeat: initial initial;"> lCh.PrintSize = <span style="color:#2b91af;">PrintSizeType</span>.Custom;
lCh.ChartObject.Height = 280;
lCh.ChartObject.Width = 400;
lCh.ChartArea.Border.IsVisible = <span style="color:blue;">false</span>; <span style="color:green;">// Remove border.</span>
<span style="color:blue;">if</span> (lCh.CategoryAxis != <span style="color:blue;">null</span>) lCh.CategoryAxis.TickLabels.RotationAngle = 0;
<span style="color:blue;">try</span> { lCh.Calculate(); }</pre>
<span style="color:blue;">var</span> lMs = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();
{
chart.ToImage(lMs, <span style="color:#2b91af;">ImageFormat</span>.Emf);
lMs.Position = 0;
<span style="color:blue;">var</span> img = <span style="color:#2b91af;">Image</span>.FromStream(lMs);
}</pre></div><div><br></div><div>With this you will be able to reproduce the new exception that I get. The chart has over 690 categories. I don't know if this is causing some problems. But I have the impression that only the number of series of the chart is limitted to 256 series maxmum, right?<br>I have noticed that when I specify small dimensions for the image, I get no exception.<br>But I want my image to be large.</div><div><br></div><div>Note that both methods <span style="font-family: Consolas; font-size: 13px;">Calculate() and </span><span style="background-color: white; font-family: Consolas; font-size: 13px;">ToImage() </span>throw an exception:</div><div><br>{"Object reference not set to an instance of an object."}</div><div><span style="background-color: white; font-family: Consolas; font-size: 13px;"><div> at . . ( , String , Int32 , Font , SizeF , , )</div><div> at . . ( , , Rectangle , Rectangle , Int32 , Boolean , )</div><div> at . .Calculate( )</div><div> at . . ( )</div><div> at . .Calculate()</div><div> at . . (Chart )</div><div> at . . (Chart , Boolean )</div><div> at . .Calculate(Chart , Boolean )</div><div> at Aspose.Cells.Charts.Chart.Calculate(Boolean , Boolean )</div><div> at Aspose.Cells.Charts.Chart.Calculate()</div><div> at del7.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\...\del7\del7\Form1.cs:line 34</div><div><br></div></span></div><div><span style="background-color: white; font-family: Consolas; font-size: 13px;"><br></span></div><div><span style="background-color: white; font-family: Consolas; font-size: 13px;"><div> at . . ( , String , Int32 , Font , SizeF , , )</div><div> at . . ( , , Rectangle , Rectangle , Int32 , Boolean , )</div><div> at . .Calculate( )</div><div> at . . ( )</div><div> at . . ()</div><div> at . . ()</div><div> at . .ToImage(Stream , ImageFormat , Chart )</div><div> at Aspose.Cells.Charts.Chart.ToImage(Stream stream, ImageFormat imageFormat)</div><div> at del7.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\...\del7\del7\Form1.cs:line 39</div></span></div><div><br></div><div>Please, let me know of any workarounds or fixes to this.</div><div><br></div><div>Best Regards,</div><div>Kostas</div></div>