AddChartFromWorkbook

AddChartFromWorkbook(IShapeCollection, float, float, IExcelDataWorkbook, string, int, bool)

Retrieves a chart from the specified Excel workbook and adds it to the end of the given shape collection at the specified coordinates.

public static IChart AddChartFromWorkbook(IShapeCollection shapes, float x, float y, 
    IExcelDataWorkbook workbook, string worksheetName, int chartIndex, bool embedAllWorkbook)
ParameterTypeDescription
shapesIShapeCollectionThe shape collection to which the chart will be added.
xSingleThe X coordinate for positioning the chart.
ySingleThe Y coordinate for positioning the chart.
workbookIExcelDataWorkbookThe Excel workbook.
worksheetNameStringThe name of the worksheet that contains the chart.
chartIndexInt32The zero-based index of the chart shape to insert. This index can be obtained using the GetChartsFromWorksheet method.
embedAllWorkbookBooleanIf true, the entire workbook will be embedded in the chart; if false, only the chart data will be embedded.

Return Value

The chart that was added to the shape collection.

Exceptions

exceptioncondition
ArgumentExceptionThrown when any required parameter is null, empty, or if the chart cannot be found in the workbook.

Examples

Example:

[C#]
IExcelDataWorkbook wb = new ExcelDataWorkbook(testFile);
using (var pres = new Presentation())
{
    ExcelWorkbookImporter.AddChartFromWorkbook(pres.Slides[0].Shapes, 10, 10, wb, worksheetName, chartName, false);
    pres.Save("result.pptx", SaveFormat.Pptx);
}

See Also


AddChartFromWorkbook(IShapeCollection, float, float, IExcelDataWorkbook, string, string, bool)

Retrieves a chart from the specified Excel workbook and adds it to the end of the given shape collection at the specified coordinates.

public static IChart AddChartFromWorkbook(IShapeCollection shapes, float x, float y, 
    IExcelDataWorkbook workbook, string worksheetName, string chartName, bool embedAllWorkbook)
ParameterTypeDescription
shapesIShapeCollectionThe shape collection to which the chart will be added.
xSingleThe X coordinate for positioning the chart.
ySingleThe Y coordinate for positioning the chart.
workbookIExcelDataWorkbookThe Excel workbook.
worksheetNameStringThe name of the worksheet that contains the chart.
chartNameStringThe name of the chart to be added.
embedAllWorkbookBooleanIf true, the entire workbook will be embedded in the chart; if false, only the chart data will be embedded.

Return Value

The chart that was added to the shape collection.

Exceptions

exceptioncondition
ArgumentExceptionThrown when any required parameter is null, empty, or if the chart cannot be found in the workbook.

Examples

Example:

[C#]
IExcelDataWorkbook wb = new ExcelDataWorkbook(testFile);
using (var pres = new Presentation())
{
    string worksheetName = "worksheet name";
    var worksheetCharts = wb.GetChartsFromWorksheet(worksheetName);
    foreach (var chart in worksheetCharts)
    {
        ISlide slide = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);
        ExcelWorkbookImporter.AddChartFromWorkbook(slide.Shapes, 10, 10, wb, worksheetName, chart.Key, false);
    }
    pres.Save("result.pptx", SaveFormat.Pptx);
}

See Also


AddChartFromWorkbook(IShapeCollection, float, float, Stream, string, string, bool)

Retrieves a chart from the specified Excel workbook and adds it to the end of the given shape collection at the specified coordinates.

public static IChart AddChartFromWorkbook(IShapeCollection shapes, float x, float y, 
    Stream workbookStream, string worksheetName, string chartName, bool embedAllWorkbook)
ParameterTypeDescription
shapesIShapeCollectionThe shape collection to which the chart will be added.
xSingleThe X coordinate for positioning the chart.
ySingleThe Y coordinate for positioning the chart.
workbookStreamStreamA stream containing the workbook data.
worksheetNameStringThe name of the worksheet that contains the chart.
chartNameStringThe name of the chart to be added.
embedAllWorkbookBooleanIf true, the entire workbook will be embedded in the chart; if false, only the chart data will be embedded.

Return Value

The chart that was added to the shape collection.

Exceptions

exceptioncondition
ArgumentExceptionThrown when any required parameter is null, empty, or if the chart cannot be found in the workbook.
InvalidOperationExceptionThrown when the input data is in an unsupported format.

Examples

Example:

[C#]
using (var fStream = new FileStream(workbookPath, FileMode.Open, FileAccess.Read))
using (var pres = new Presentation())
{
    ExcelWorkbookImporter.AddChartFromWorkbook(pres.LayoutSlides[0].Shapes, 10, 10, fStream, worksheetName, chartName, true);
    pres.Save("result.pptx", SaveFormat.Pptx);
}

See Also


AddChartFromWorkbook(IShapeCollection, float, float, string, string, string, bool)

Retrieves a chart from the specified Excel workbook and adds it to the end of the given shape collection at the specified coordinates.

public static IChart AddChartFromWorkbook(IShapeCollection shapes, float x, float y, 
    string workbookPath, string worksheetName, string chartName, bool embedWorkbook)
ParameterTypeDescription
shapesIShapeCollectionThe shape collection to which the chart will be added.
xSingleThe X coordinate for positioning the chart.
ySingleThe Y coordinate for positioning the chart.
workbookPathStringThe file path to the workbook containing the chart.
worksheetNameStringThe name of the worksheet that contains the chart.
chartNameStringThe name of the chart to be added.
embedWorkbookBooleanIf true, the workbook will be embedded in the chart; if false, the chart will link to the external workbook.

Return Value

The chart that was added to the shape collection.

Exceptions

exceptioncondition
ArgumentExceptionThrown when any required parameter is null, empty, or if the chart cannot be found in the workbook.
IOExceptionThrown when an I/O error occurs while accessing the file.
InvalidOperationExceptionThrown when the input data is in an unsupported format.

Examples

Example:

[C#]
using (var pres = new Presentation())
{
    ExcelWorkbookImporter.AddChartFromWorkbook(pres.Slides[0].Shapes, 10, 10, workbookPath, worksheetName, chartName, false);
    pres.Save("result.pptx", SaveFormat.Pptx);
}

See Also