Chart image when embedded on oleframe resized on doubleclick in ppt

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

Hi Satish,


I have worked with the sample code shared and have modified this for your convenience. You can observe from the generated presentation in shared zip file. Please share, if I may help you further in this regard.

Many Thanks,

hi,

Still chart image is resized. it is shrinked. i tried ur code. pls give me more accurate solution for this isssue. And thanks for ur reply.

Hi Satish,


Can you please share the generated presentation on your end along with snapshot highlighting the issue. Please also share the desired output for reference. I will investigate the issue further on my end to help you out. Have you observed the generated presentation shared by me as well.

Many Thanks,

Hi Mudassir,

I am attaching the source file for your reference. Open the Testolechart.ppt and see the two slides. The first slide is double clicked and chart got resized. Second slide chart image is original which is exported. I would like to point that i have set picturebox size as chartobject size. And please tell me how to equal chart object size with oleframesize. And please give me solution for this problem as soon as possible since my project is in delivery phase.

Thanks in advance

Hi Satish,


I have worked with the sample project shared on my end with a only change that I included license in the sample code. I have obtained the shared presentation and have not been able to observe any resizing issue. Please observe the actual and resized charts in attached presentation. Please observe the size of two ole frames and they are same. I don’t find any issue in the output. Please share, if I may help you further in this regard.

Many Thanks,

Hi Mudassir,

Thanks for your quick response. i would like to point that when i am setting chartobject width and height

for eg. chart.chartobject.width=450

chart.chartobject.height=400

chart get resized.

i tried without setting chart object width and height. Chart is not resized. But the fonts of datalabels legends gets resized.

For eg. chart.nseries(0).datalabels.font.size=16

But when i double clicked font size became smaller than 16.

Please reply as soon as possible as my project is in delivery phase.

Hi Satish,


I have observed the code sample shared. You need to set the chart size in accordance with the Ole frame and Workbook size that you are setting. I have made the following modification in the sample code. For your kind reference, the generated presentation is added. Please share, if I may help you further in this regard.

_chart.ChartObject.Width = 684 '=5472/8
_chart.ChartObject.Height = 288 '=2304/8

Many Thanks,

Hi Mudassir,

What about the font size? When i double click fonts in chart get smaller. Please give me solution quickly. Please refer previous query for more info..

And please confrm oleframe size is 8times of chartobject size?

Hi,


I have worked over your requirement to further details. I have modified the sample code shared and have made some changes in Aspose.Cells end code to generate the Ole frame slide as it is generated by PowerPoint. Please observe TestOleChart3.ppt (generated by Aspose) and Added Through PowerPoint.ppt (generated by PowerPoint). You can observe the two presentations that they are similar to a great deal. With sample code you can play further to set to chart area or legend position to get the same ole frame as it is obtained from PowerPoint. I have shared the comparison images, Issue_Image 1.jpeg and Issue_Image 2.jpeg as well for your convenience to highlight the issue and some background theory. I also like to add further here is that when you add excel chart inside presentation using Ole frame, every thing is done using MS Ole engine and Aspose.Slides adds the ole frame as it is.

In order to have better effects as per your requirements you may need to make changes in Aspose.Cells end and then add the chart as Ole frame. In this regard, I humbly suggest you to please contact Aspose.Cells forum further in this regard for appropriate Aspose.Cells chart formatting and its addition to PowerPoint presentation as ole frame using Aspose.Slides.

For your question related to Ole frame size 8 times of chart object, I like to add that Aspose.Slides has default slide size 720 x 540 ( 720 * 8=5760 and 540 * 8= 4320). The size 720 x 540 in inches is actually equal to 10’’ x 7.5’’ as there are 576 pixels per inch for Aspose.Slides. So, in order to map the size of Aspose.Slides pixel size to Aspose.Cells this mapping is done. I hope this will clear the concept to you.

Many Thanks,

Hi Mudassir,

I have checked your sample ppt. Chart not distorted. I have used the same code and applied my license. But chart get resized. Please look into this issue and give me a perfect and absolute solution

Please check my ppt for clear understanding.

Hi,


I have downloaded the sample code shared and it is infact the same that I shared with you. I have generated the presentation and tested the Ole frame on my end for generated presentation without any issue. Moreover, I observed the disabled Ole frame in yours shared presentation and enabled it on my end and have not observed any issue even in that as well. For your convenience, I have attached yours shared presentation with Ole frame on slide 1 modified by me and presentation generated by your sample code on my end. Also, I am using PowerPoint 2010 on my end and I have attached the image highlighting the version on PowerPoint on my end. Unfortunately, I am unable to reproduce the issue on my end. Please share, if I may help you further in this regard.

Secondly, I also like to add that as you have mentioned in the sample code that I have made changes in Excels chart using Aspose.Cells to get that look fit in Ole frame. So, I may suggest you to please contact Aspose.Cells forum in this regard for your further kind reference.

Many Thanks,

Hi Mudassir,

I don't know whether you understood my problem. I told that chart get resized after double clicking. I have used the same code shared by you. I also checked the ppt(Testolechart4.ppt) shared by you. In that also chart get resized. I am keep on posting this issue. But no proper solution from your side.Or escalate the issue to development team and do the needful. You can again check your ppt and my ppt and the code shared.

Please give me perfect solution this time. And see previous posts for reference.

Hi Satish,


We are sorry for your inconvenience. As I shared with you in my earlier posts that the issue involves support from Aspose.Cells. We are internally discussing the issue for any possible solution and will share the feedback with you as soon as it will be available.

Many Thanks,

Hi Mudassir,

I posted this issue in Aspose.cells team also. But no response. When you double click the chart object , oleframes size is same only but the chart plotted inside the frame get resized

I have used the same code as i shared but used my license. Please refer previous posts for code.

Eg:

(before double cick )

oleframe size 500

chart size 500

(after double click)

oleframe size remains same

but chart size becomes bigger

Please look into this matter and do the needful. we have bought this product but no proper support from your side.

Give me solution for this

Link for the post in aspose.cells

<A href="https://forum.aspose.com/t/94393</A></P>

Hi Satish,


I have observed the issue stated by you and like to share that the before and after images shared by you are two separate things. As far as Ole size is concerned, it is remaining same before and enabling Ole frame by applying mapping mechanism.

Now, coming to your question of chart resizing. In before double click image, you are generating the chart image using Aspose.Cells. The same image is being set for Ole frame image. For your convenience, I have attached the image of chart that I generated using Aspose.Cells and set for Ole frame inside Aspose.Slides. I saved the same image to file for reference. You can see from the source chart image generated using Aspose.Cells that is being set for Ole frame that it is same as one shared by you over this link in before double click image. Then you, double click on image and MS Ole Engine play its role and enable the chart and share a perspective of same chart as Ole object that is bit more zoomed than the one in the chart image taken using Aspose.Cells previously. What you are trying to compare is to image with Ole object, which in my humble opinion is not right. As far as Aspose.Slides is concerned, it has provided the correct mapping of ole frame size and that you have also shared remains same. Aspose.Slides generated presentation display the zoomed perspective of chart in enabled form and in disabled form display the image that is generated by Aspose.Cells with different perspective.

Aspose.Cells may provide if possible help to you in this regard in two ways. First could be to use if some possible options of Aspose.Cells to generate the chart image with same perceptive as it appears when the chart is in enabled form ( a bit more zoomed chart). The second option can be to set the chart values for plot area in using Aspose.Cells so that it looks the same in enabled Ole form as in the shared chart image. In either cases it lies on Aspose.Cells end and you may please consult Aspose.Cells team in this regard. I hope this will elaborate the concept and situation to you.

Many Thanks,