Pasting excel range into aspose slides

Hello,

I am currently using aspose cells for .net and slides for .net. We were using vba to paste a range of excel cells into a powerpoint slide using the following code:

If IsMissing(enhancedMetaFile) Then
wb.Application.Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
PPSlide.Shapes.Paste.Select
Else
wb.Application.Selection.Copy
PPSlide.Shapes.PasteSpecial(ppPasteEnhancedMetafile).Select
End If

Dim sr As PowerPoint.ShapeRange
Set sr = ppApp.ActiveWindow.Selection.ShapeRange

We get a range from the excel spreadsheet to copy to the powerpoint presentation.

How would we do this with Aspose?

Hello Dear,

Please use the code snippet given below to add the particular cells from excel file as image in Aspose.Slides .NET. Please share with us, if you may feel any issue.

Workbook book = new Workbook("D:\\Aspose Data\\Book1.xls");

Presentation pres = new Presentation();

Slide slide;

Aspose.Cells.Rendering.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();

imgOptions.ImageFormat = ImageFormat.Emf;

imgOptions.HorizontalResolution = 200;

imgOptions.VerticalResolution = 200;

Worksheet sheet = book.Worksheets[0];

int iImageIndex;

ImageEx Imag;

//Set the print area accroding to your desired range of cells for which

//you want the image to be taken.

sheet.PageSetup.PrintArea = "A1:C30";

MemoryStream ImageMs;

Picture pic;

Aspose.Slides.Shape ImgShape;

Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, imgOptions);

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

{

ImageMs = new MemoryStream();

sr.ToImage(j, "D:\\Aspose Data\\cellrange_" + sheet.Index + j + ".emf");

sr.ToImage(j, ImageMs);

slide = pres.AddEmptySlide();

pic=new Picture(pres,ImageMs);

iImageIndex=pres.Pictures.Add(pic);

ImgShape = slide.Shapes.AddPictureFrame(iImageIndex, 200, 400, 500, 700);

}

pres.Write("D:\\Aspose Data\\NewPres.ppt");

Thanks and Regard,