Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

ExcelApplication supports all Excel chart types, and allows you to insert a chart in a worksheet, create a chart sheet (a worksheet that only contains a chart).

If you open an existing Excel file with ExcelApplication.Open, you can use ExcelWriter's charting objects to modify charts in the spreadsheet.

To create a simple column chart:

  1. Get a Charts collection:
    The Charts collection contains all charts in a specified worksheet.
    # Create an anchor in the worksheet:
    An anchor represents the position of a floating object (e.g., a chart) within a worksheet. The chart's top left corner will be placed at the anchor.
    # Create a blank chart of a specified type, at the anchor you created:
    The ChartType class contains all available chart types (e.g., Column) and sub-types (e.g., Clustered).
    # Return a SeriesCollection object representing the set of data series in the chart:
  2. Set the range of category (x) axis values:
  3. Add a data series to the chart:
    The formula passed to CreateSeries represents cells that contain the source values for the new data series.

Example: Creating a Chart

Modifying an Existing Chart

Code sample: Modifying an Existing Chart

[C#] | [VB.NET]
When you use ExcelApplication to open a spreadsheet, you can access charts through their names or titles. Chart.getTitle returns a ChartText object representing the title region. ChartText.getText returns the title text. The following function takes a chart's title and returns a Chart object representing the chart. This code can be useful if you want to locate a specific chart in a worksheet but only know its title text:

The following example uses the FindChart code to locate a specific chart in a worksheet. The chart series collection is then cleared and re-set to the data imported from a database:

  • No labels