Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Remarks

To create a Chartsheet, use Worksheets.createChartsheet(). To get an existing Chartsheet, get a Worksheet using Workbook.Worksheets[i] and check if it is of type Chartsheet.

Some Worksheet properties are not valid on a Chartsheet. For more details on the behavior of individual properties on Chartsheets, refer to the individual property descriptions and the Worksheet documentation.

Example
Code Block
csharp
csharp
titleC#

          //--- Create a Chartsheet
          ExcelApplication xla = new ExcelApplication();
          Workbook wb = xla.Create();
          Worksheet ws = wb.Worksheets[0];
          Chartsheet cs = wb.Worksheets.CreateChartsheet
               (ChartType.Pie.Pie3D, "Chart");

          //--- Get the first Chartsheet from a Workbook
          ExcelApplication xla = new ExcelApplication();
          Workbook wb = xla.Open("C:\\MySpreadsheet.xls");
          bool found = false;
          for(int i = 0; i < wb.Worksheets.Count; i++)
          {
               if (found == false)
               {
                    Worksheet ws = wb.Worksheets[i];
                    
                    if(ws is Chartsheet)
                    {
                         Chartsheet cs = (Chartsheet)ws;
                         found = true;
                    }
               }
          }
        
Code Block
vb.net
vb.net
titlevb.net

          '--- Create a Chartsheet
          Dim xla As New ExcelApplication()
          Dim wb As Workbook = xla.Create()
          Dim ws As Worksheet = wb.Worksheets(0)
          Dim cs As Chartsheet = wb.Worksheets.CreateChartsheet _
               (ChartType.Pie.Pie3D, "Chart")

          '--- Get the first Chartsheet from a Workbook
          Dim xla As New ExcelApplication()
          Dim wb As Workbook = xla.Open("C:\MySpreadsheet.xls")
          Dim found As Boolean = False
          Dim i As Integer
          For i = 0 To wb.Worksheets.Count - 1
               If found = False Then
                    Dim ws As Worksheet = wb.Worksheets(i)

                    If ws Is Chartsheet Then
                         Dim cs As Chartsheet = CType(ws, Chartsheet)
                         found = True
                    End If
               End If
          Next
        

...