This is my sample code
using Aspose.Cells;
using Aspose.Cells.Rendering;
using Aspose.Slides;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Scaling
{
static void Main(string[] args)
{
WorkbookDesigner workbookDesigner = new WorkbookDesigner();
workbookDesigner.Workbook = new Workbook(@“C:\Users\singhs102\Desktop\PPTX\AsposeTest.xls”);
Presentation presentation = new Presentation(@"C:\Users\singhs102\Desktop\PPTX\AsposeTest.ppt");
ISlide slide = presentation.Slides[0];
AddOleFrame(slide, 0, 15, 0, 3, 0, 300, 1100, 0, 0, presentation, workbookDesigner, true, 0, 0);
String fileName = @"C:\Users\singhs102\Desktop\PPTX\AsposeTest_Ole.ppt";
presentation.Save(fileName, Aspose.Slides.Export.SaveFormat.Ppt);
}
/Methods used******/
private static void SetOleAccordingToCustomHeighWidth(Workbook workbook, Int32 startRow,
Int32 endRow, Int32 startCol, Int32 endCol, double slideWidth, double slideHeight, Int32 dataSheetIdx)
{
Worksheet work = workbook.Worksheets[dataSheetIdx];
double actualHeight = 0, actualWidth = 0;
double newHeight = slideHeight;
double newWidth = slideWidth;
double tem = 0;
double newTem = 0;
for (int i = startRow; i <= endRow; i++)
actualHeight += work.Cells.GetRowHeightInch(i);
for (int i = startCol; i <= endCol; i++)
actualWidth += work.Cells.GetColumnWidthInch(i);
///Setting new Row and Column Height
for (int i = startRow; i <= endRow; i++)
{
tem = work.Cells.GetRowHeightInch(i);
newTem = (tem / actualHeight) * newHeight;
work.Cells.SetRowHeightInch(i, newTem);
}
for (int i = startCol; i <= endCol; i++)
{
tem = work.Cells.GetColumnWidthInch(i);
newTem = (tem / actualWidth) * newWidth;
work.Cells.SetColumnWidthInch(i, newTem);
}
}
private static void AddOleFrame(ISlide slide, Int32 startRow, Int32 endRow, Int32 startCol, Int32 endCol,
Int32 dataSheetIdx, Int32 x, Int32 y, Double OleWidth, Double OleHeight,
Presentation presentation, WorkbookDesigner workbookDesigner,
Boolean onePagePerSheet, Int32 outputWidth, Int32 outputHeight)
{
String tempFileName = @"C:\Users\singhs102\Desktop\PPTX\icon";
if (startRow == 0)
{
startRow++;
endRow++;
}
//Setting active sheet index of workbook
workbookDesigner.Workbook.Worksheets.ActiveSheetIndex = dataSheetIdx;
//Getting Workbook and selected worksheet
Workbook workbook = workbookDesigner.Workbook;
Worksheet work = workbook.Worksheets[dataSheetIdx];
//Scaling rows height and coluumns width according to custom Ole size
double height = OleHeight / 576f;
double width = OleWidth / 576f;
SetOleAccordingToCustomHeighWidth(workbook, startRow, endRow, startCol, endCol, width, height, dataSheetIdx);
//Set Ole Size in Workbook
workbook.Worksheets.SetOleSize(startRow, endRow, startCol, endCol);
workbook.Worksheets[0].IsGridlinesVisible = false;
//Setting Image Options to take the worksheet Image
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Bmp;
imageOrPrintOptions.OnePagePerSheet = onePagePerSheet;
SheetRender render = new SheetRender(workbookDesigner.Workbook.Worksheets[dataSheetIdx], imageOrPrintOptions);
String ext = ".bmp";
//render.ToImage(0, tempFileName + ext);
//Image image = ScaleImage(Image.FromFile(tempFileName + ext), outputWidth, outputHeight);
//String newTempFileName = tempFileName+"1" + ext;
//image.Save(newTempFileName, ImageFormat.Bmp);
render.ToImage(0, tempFileName);
Image image = ScaleImage(Image.FromFile(tempFileName + ext), outputWidth, outputHeight);
String newTempFileName = tempFileName + "1" + ext;
image.Save(newTempFileName, ImageFormat.Bmp);
//render.ToImage(0, @"C:\Users\singhs102\Desktop\PPTX\download.jpg");
//Image img = Image.FromFile(@"C:\Users\singhs102\Desktop\PPTX\download.bmp");
//Adding Image to slide picture collection
//Picture pic = new Picture(presentation, newTempFileName);
//int picId = presentation.Pictures.Add(pic);
IPPImage pic = presentation.Images.AddImage(image);
//Saving worbook to stream and copying in byte array
Stream mstream = workbook.SaveToStream();
byte[] chartOleData = new byte[mstream.Length];
mstream.Position = 0;
mstream.Read(chartOleData, 0, chartOleData.Length);
//Adding Ole Object frame
IOleObjectFrame oleObjectFrame = slide.Shapes.AddOleObjectFrame(x, y, Convert.ToInt32(OleWidth),
Convert.ToInt32(OleHeight), "Excel.Sheet.8", chartOleData);
//Setting ole frame Imnae and Alternative Text property
oleObjectFrame.FillFormat.PictureFillFormat.Picture.Image = pic;
oleObjectFrame.AlternativeText = "image" + "Alt";
//image.Dispose();
}
private static Image ScaleImage(Image image, Int32 outputWidth, Int32 outputHeight)
{
if (outputWidth == 0 && outputHeight == 0)
{
outputWidth = image.Width;
outputHeight = image.Height;
}
Bitmap outputImage = new Bitmap(outputWidth, outputHeight, image.PixelFormat);
outputImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
Graphics graphics = Graphics.FromImage(outputImage);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
System.Drawing.Rectangle srcDestRect = new System.Drawing.Rectangle(0, 0, outputWidth, outputHeight);
graphics.DrawImage(image, srcDestRect, srcDestRect, GraphicsUnit.Pixel);
graphics.Dispose();
return outputImage;
}
}
}