Exception merging excel sheet into word

Hi,

I am attempting to merge the attached excel file into a new word doc, using the code below. However I am getting an the exception below for the first sheet in the file. The other sheets are merged fine.
Could you please investigage,

thanks,

Brian

+ [System.NullReferenceException] {“Object reference not set to an instance of an object.”}
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
System.NullReferenceException

StackTrace " at Aspose.Cells.Cell.set_x85274cd6fd4e259a(Byte xbcea506a33cf9111)\r\n at xd8ca772c9f198583.x658c13c9c9ee7e4d.xf9442a544559e175(Worksheet x4ad48b2bd5f524f6, Boolean x79237be573698daf)\r\n at xd8ca772c9f198583.x658c13c9c9ee7e4d.xf597a57dbb4543d0(Int32 x69e9b567129e96cb, String xb469c015ff0466a1)\r\n at xd8ca772c9f198583.x658c13c9c9ee7e4d.x83e84e1d3bc59160(Boolean x6fb303b00fe33226, Int32 x69e9b567129e96cb)\r\n at Aspose.Cells.Worksheet.SheetToImage(Boolean isPaginate)\r\n at Aspose.Cells.Worksheet.SheetToImage()\r\n at DocBuilder.DocumentWriter.AddAttachment(String sourceDocumentFullPath) in C:\development\workspace\DocBuilder\BLL\DocumentWriter.cs:line 205" string



//Create a new Workbook object.
Workbook book = new Workbook(sourceDocumentFullPath);
//Get the first worksheet.
int count = book.Worksheets.Count;
for (int i = 1; i <= count; i++)
{
Worksheet sheet = book.Worksheets[i - 1];
if (sheet != null)
{
try
{
//Convert the worksheet to image.
System.Drawing.Bitmap bitmap = sheet.SheetToImage();

if (bitmap != null)
{
builder.InsertImage(bitmap);
}
}
catch (Exception e)
{
Log.logError("DocumentWriter.AddAttachment: Error adding sheet " + i + " of document " + sourceDocumentFullPath, “error”);
}
}

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I will move your request to the Aspose.Cells forum. My colleagues will answer you shortly.

Best regards,

Hi,

Well, you are using older Sheet.SheetToImage method which is not recommended now, this method would be obsoleted soon. We recommend you to use SheetRender API instead and also use latest version in which we have made lots of enhancements regarding Sheet-to-Image feature.
Please try the attached version and here is the sample code that works fine as I tested with your file.

Sample code:

//Create a new Workbook object.
Workbook book = new Workbook(“e:\test2\sampleFile.xlsx”);
//Get the first worksheet.
int count = book.Worksheets.Count;

//Define ImageOrPrintOptions
Aspose.Cells.Rendering.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();
//Specify the image format
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Bmp;


for (int i = 1; i <= count; i++)
{
Worksheet sheet = book.Worksheets[i - 1];
if (sheet != null)
{


//Render the sheet with respect to specified image/print options
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, imgOptions);

for (int j = 0; j < sr.PageCount; j++)
{

sr.ToImage(j, “e:\test2\outimg_” + sheet.Name + j + “.bmp”);
}

//…

}

}


Moreover, please see the documents for your complete reference about Sheet-to-Image feature.
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/converting-worksheet-to-image.html
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/converting-worksheet-to-image-worksheet-to-image-by-page.html
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/converting-worksheet-to-image-using-imageorprint-options.html



Thank you.