| xlsgen > overview > Chart picture insertion |

When pictures are added in charts, they move with the chart, are deleted when the chart is deleted, and so on. xlsgen makes it easy to add pictures in charts.
The only difference between inserting a picture in the sheet (free from the chart) and inserting a picture in the chart is the coordinate system (left/right/top/bottom). In the latter, the coordinate system is expressed in 1/4000-th of respectively the width and the height of the chart.
Here is an example in C++ :
| C/C++ code |
xlsgen::IXlsWorkbookPtr wbk = engine->New( L"chart_picinside.xls");
xlsgen::IXlsWorksheetPtr wksht = wbk->AddWorksheet( L"Sheet1" );
wksht->Label[2][2] = L"Janvier";
wksht->Label[3][2] = L"Février";
wksht->Label[4][2] = L"Mars";
wksht->Label[1][3] = L"2000";
wksht->Number[2][3] = 2;
wksht->Number[3][3] = 6;
wksht->Number[4][3] = 5;
wksht->Label[1][4] = L"2001";
wksht->Number[2][4] = 3;
wksht->Number[3][4] = 7;
wksht->Number[4][4] = 6;
wksht->Label[1][5] = L"2002";
wksht->Number[2][5] = 4;
wksht->Number[3][5] = 8;
wksht->Number[4][5] = 7;
wksht->Label[1][6] = L"2003";
wksht->Number[2][6] = 5;
wksht->Number[3][6] = 9;
wksht->Number[4][6] = 5;
xlsgen::IXlsChartPtr chart = wksht->NewChart(xlsgen::charttype_bar2D,
8, //row1
1, //col1
16, //row2
5 //col2
);
xlsgen::IXlsChartDataSourcePtr datasource = chart->DataSource;
datasource->SeriesInRows = TRUE;
datasource->Range = L"R1C2:R4C6";
xlsgen::IXlsPicturePtr pic = chart->Shapes->Pictures->Add(L"input\\pic300x200.png");
pic->LeftColumn = 3000; // 1/4000-th of the width of the chart
pic->RightColumn = 4000; // 1/4000-th of the width of the chart
pic->TopCell = 3; // 1/4000-th of the height of the chart
pic->BottomCell = 700; // 1/4000-th of the height of the chart
pic->AlternativeText = L"my alternative text";
wbk->Close();
|
xlsgen documentation. © ARsT Design all rights reserved.