How to use Chart.Placement.getValues or something else to get the location of a Chart

I was wondering how to use the method Chart.Placement.getValues?

I'm trying to determine the location of a chart in an existing Excel document. If this is the wrong method please let me know what I should use to get the location of a chart.

Daryl

Hi Daryl,

Please use the following to get the location of the chart in the worksheet.

int statrow = chart.ChartObject.UpperLeftRow;

int startcol = chart.ChartObject.UpperLeftColumn;

int endrow = chart.ChartObject.LowerRightRow;

int endcol = chart.ChartObject.LowerRightColumn;

Thank you.

I guess I'm missing something. The chart object doesn't cotain a ChartObject. According to the API document the UpperLeftRow and other properties listed above exist in the ChartShape object. I couldn't find an example of how to reference the ChartShape object in the documentation. I guess I'm a little confused.

Here's my code. I open an existing worksheet that contains some sheets already. I add a new sheet and then add a chart to it. I would like to find out where the newly created chart is located. This is only test code. Once I have the correct code to find the properties you listed above I will be modifying this code to collect all the charts and their locations in a workbook so I can replace them with images. I then want to convert the updated workbook with the chart images to pdf. This is a work around because the pdf convert utility for cells doesn't convert the charts.

Would you please instruct me as to what I'm doing incorrectly?

Thanks,

Daryl

VB.NET Code:

doc.Worksheets.Add(SheetType.Worksheet)

Dim ws2 As Worksheet = doc.Worksheets(intSheetCount + 1)

Dim cells As Aspose.Cells.Cells = ws2.Cells

cells(0, 1).PutValue("Income")

cells(1, 0).PutValue("Company A")

cells(2, 0).PutValue("Company B")

cells(3, 0).PutValue("Company C")

cells(1, 1).PutValue(10000)

cells(2, 1).PutValue(20000)

cells(3, 1).PutValue(30000)

Dim chartIndex As Integer = ws2.Charts.Add(ChartType.Column, 9, 9, 21, 15)

Dim mychart As Chart = ws2.Charts(chartIndex)

mychart.NSeries.Add("B2:B4", True)

mychart.NSeries.CategoryData = "A2:A4"

Dim aSeries As ASeries = mychart.NSeries(0)

aSeries.Name = "B1"

mychart.IsLegendShown = True

mychart.Title.Text = "Income Analysis"

ws2.Name = "Hello Daryl"

'Get the current location of the chart

Dim intStartRow As Integer

Dim intStartCol As Integer

Dim intEndRow As Integer

Dim intEndCol As Integer

intStartRow = mychart.ChartObject.UpperLeftRow

intStartCol = mychart.ChartObject.UpperLeftColumn

intEndRow = mychart.ChartObject.LowerRightRow

intEndCol = mychart.ChartObject.LowerRightColumn

Dim bitmap As Bitmap

bitmap = mychart.ToImage()

bitmap.Save("C:\Temp\Chart1.bmp")

ws2.Pictures.Add(9, 9, "C:\Temp\Chart1.bmp")

doc.Save("C:\temp\ChartIncluded.xls")

Hi Daryl,

Which version of Aspose.Cells you are using? I think you are not using the latest fix (4.2.0.10). And for your info, recently, we have enhanced XLS2PDF conversion. Now you may directly convert an excel file(containing charts) to PDF format.

Please try the attached version.

Thank you.

I tried this and it works to convert an Excel with chart to a spreadsheet. I was using an earlier version from this forum: http://www.aspose.com/Community/Forums/77130/ShowThread.aspx#77130

The version you attached didn't fix the error I get on the other thread but it does show I can convert charts.

Thank you very much.

Daryl