Hi,
I tried the above code. oleobject size remains same after double clicking but chart image and ppt contents becomes bigger or zoomed. Could you please help me in finding solution for this.... I have to finish the project. Please reply.... I have attached vb project file for your reference
Here is the code:(vb.net)
Imports Aspose.Slides
Imports Aspose.Cells
Imports Aspose.Cells.Charts
Imports Aspose.Cells.Charts.Series
Imports System.IO
Public Class Form1
Shared Sub AddExcelChartInPresentation(ByVal pres As Presentation, ByVal sld As Slide, ByVal wbStream As MemoryStream, ByVal imgChart As Bitmap)
Dim pic As Aspose.Slides.Picture = New Aspose.Slides.Picture(pres, imgChart)
Dim picId As Integer = pres.Pictures.Add(pic)
Dim desiredHeight As Integer = 2304 '4 inch (4 * 576)
Dim desiredWidth As Integer = 5472 '9.5 inch (9.5 * 576)
Dim shapeHeader As Shape = sld.Shapes.AddRectangle(80, 80, desiredWidth - 80, 200)
shapeHeader.LineFormat.ShowLines = False
Dim tf1 As TextFrame = shapeHeader.AddTextFrame("barchart")
tf1.AnchorText = AnchorText.Top
Dim port1 As Portion = tf1.Paragraphs(0).Portions(0)
port1.FontBold = True
port1.FontHeight = 12
port1.FontColor = Color.Black
pres.Fonts(0).FontName = "calibri"
Dim oof As OleObjectFrame = sld.Shapes.AddOleObjectFrame(0, 400, desiredWidth, desiredHeight, "Excel.Sheet.8", wbStream.ToArray())
oof.PictureId = picId
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Step - 1: Create an excel chart using Aspose.Cells
'--------------------------------------------------
'Create a workbook
Dim wb As Workbook = New Workbook()
'Add an excel chart
Dim chartRows As Integer = 55
Dim chartCols As Integer = 25
Dim cellsName As String() = { _
"A1", "A2", "A3", "A4", _
"B1", "B2", "B3", "B4", _
"C1", "C2", "C3", "C4", _
"D1", "D2", "D3", "D4", _
"E1", "E2", "E3", "E4" _
}
'Array of cell data
Dim cellsValue As Integer() = { _
67, 86, 68, 91, _
44, 64, 89, 48, _
46, 97, 78, 60, _
43, 29, 69, 26, _
24, 40, 38, 25 _
}
'Add a new worksheet to populate cells with data
Dim dataSheetIdx As Integer = wb.Worksheets.Add()
Dim dataSheet As Worksheet = wb.Worksheets(dataSheetIdx)
Dim sheetName As String = "DataSheet"
dataSheet.Name = sheetName
'Populate DataSheet with data
For i As Integer = 0 To cellsName.Length - 1
Dim cellName As String = cellsName(i)
Dim cellValue As Integer = cellsValue(i)
dataSheet.Cells(cellName).PutValue(cellValue)
Next
'Add a chart sheet
Dim chartSheetIdx As Integer = wb.Worksheets.Add(SheetType.Chart)
Dim chartSheet As Worksheet = wb.Worksheets(chartSheetIdx)
chartSheet.Name = "ChartSheet"
'Add a chart in ChartSheet with data series from DataSheet
Dim chartIdx As Integer = chartSheet.Charts.Add(ChartType.Column, 0, chartRows, 0, chartCols)
Dim _chart As Chart = chartSheet.Charts(chartIdx)
_chart.NSeries.Add(sheetName + "!A1:E1", False)
_chart.NSeries.Add(sheetName + "!A2:E2", False)
_chart.NSeries.Add(sheetName + "!A3:E3", False)
_chart.NSeries.Add(sheetName + "!A4:E4", False)
_chart.Legend.Font.Size = 8
_chart.CategoryAxis.TickLabels.Font.Size = 8
_chart.ValueAxis.TickLabels.Font.Size = 8
For i = 0 To _chart.NSeries.Count - 1
_chart.NSeries(i).DataLabels.Font.Size = 8
Next i
'Set ChartSheet an active sheet
_chart.SizeWithWindow = False
_chart.ChartObject.Width = CInt(Fix((5472 / 576.0F) * 96.0F * 0.98F))
_chart.ChartObject.Height = CInt(Fix((2304 / 576.0F) * 96.0F * 0.98F))
wb.Settings.WindowWidthInch = 5472 / 576.0F
wb.Settings.WindowHeightInch = 2304 / 576.0F
wb.Worksheets.ActiveSheetIndex = chartSheetIdx
'Dim chartSheetIndex As Integer = AddExcelChartInWorkbook(wb, chartRows, chartCols)
'Step - 2: Set the OLE size of the chart. using Aspose.Cells
'-----------------------------------------------------------
Dim r As Integer = dataSheet.Cells.GetRowHeightInch(0) * 576
Dim c As Integer = dataSheet.Cells.GetColumnWidthInch(0) * 5 * 576
'wb.Worksheets.SetOleSize(0, 5472 / 576, 0, 2304 / 576)
' wb.Worksheets.SetOleSize(0, r, 0, c)
'Step - 3: Get the image of the chart with Aspose.Cells
'-----------------------------------------------------------
wb.Worksheets(chartSheetIdx).Charts(0).ChartArea.Width = 700
Dim imgChart As Bitmap = wb.Worksheets(chartSheetIdx).Charts(0).ToImage()
'Save the workbook to stream
Dim wbStream As MemoryStream = wb.SaveToStream()
'Step - 4 AND 5
'-----------------------------------------------------------
'Step - 4: Embed the chart as an OLE object inside .ppt presentation using Aspose.Slides
'-----------------------------------------------------------
'Step - 5: Replace the object changed image with the image obtained in step 3 to cater Object Changed Issue
'-----------------------------------------------------------
'Create a presentation
Dim pres As Presentation = New Presentation()
Dim sld As Slide = pres.GetSlideByPosition(1)
'Add the workbook on slide
AddExcelChartInPresentation(pres, sld, wbStream, imgChart)
'Step - 6: Write the output presentation on disk
'-----------------------------------------------------------
pres.Write("c:\test\output2.ppt")
End Sub
End Class