Page tree

Versions Compared

Key

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

...

In

...

addition

...

to

...

Charts

...

,

...

ExcelApplication

...

allows

...

you

...

to

...

add

...

the

...

following

...

drawing

...

objects

...

to

...

a

...

worksheet:

...

  • Comments
    A comment is a note attached to a cell, or group of merged cells, that is separate from other cell content. A comment is represented by a Comment object.
     
  • Pictures
    A picture is a JPEG, PNG, BMP, or GIF image that is inserted in the worksheet. A picture is represented by a Picture object.

  • Shapes
    A shape may be one of Excel's ready-made AutoShapes or the display area of a comment or picture. A shape is represented by a Shape object.

 
Adding a Comment to a Worksheet

A comment must be associated with a cell. Once created, comments may not be moved between cells. To create a comment:

  1. Use the property Cell.Comment to return a Comment object.

    Code Block
    languagec#
     ExcelApplication xla = new ExcelApplication();
    Workbook wb = xla.Create();
    Worksheet ws = wb.Worksheets[0];
    
    Cell cellB5 = ws.Cells["B5"];
    Comment comm = cellB5.Comment;

...

  1. Add text to the comment.

    Code Block
    comm.Text = "Figures for March are projected.";

...

  1. Specify the author of the comment.

    Code Block
    comm.Author = "John Doe";

...

  1. Set whether the comment will be visible when the document is opened in Excel. By default, the comment will be hidden, and will be displayed only if the user hovers over the comment's cell.

    Code Block
    comm.Visible = true;

...

  1. To modify the comment's

...

  1. display

...

  1. area,

...

  1. return

...

  1. its

...

  1. Shape

...

  1. object

...

  1. and

...

  1. set

...

  1. Shape

...

  1. properties,

...

  1. for

...

  1. example:

...

  1. Code Block
    Shape commShape = comm.Shape;
    commShape.FillColor = oColor;
    commShape.FitToText = true;

...

  1. Image Added

Creating a Picture

Pictures in a worksheet are stored in the Pictures collection. To add a picture to a worksheet:

  1. Return a Pictures collection.

    Code Block
    ExcelApplication xla = new ExcelApplication();
    Workbook wb = xla.Create();
    Worksheet ws = wb.Worksheets[0];
    Pictures pics = ws.Pictures;

...

  1. Create a Picture object from a JPEG, PNG, BMP, or GIF image and insert it at a specified anchor in the worksheet. The anchor represents the position of the top-left corner of the picture in the worksheet.

    Code Block
    string imgPath = @"c:\images\owlogo.jpg";
    Anchor anch = ws.CreateAnchor(0, 7, 0, 0);
    Picture pic = pics.CreatePicture(imgPath, anch);

...

  1. To modify the size,

...

  1. position,

...

  1. or

...

  1. formatting

...

  1. of

...

  1. a

...

  1. Picture,

...

  1. return

...

  1. its

...

  1. Shape

...

  1. object

...

  1. and

...

  1. set

...

  1. Shape

...

  1. properties,

...

  1. for

...

  1. example:

...

  1. Code Block
    Shape picShape = pic.Shape;
    picShape.Rotation = 45;

...

Creating an AutoShape

Excel's

...

ready-made

...

AutoShapes

...

are

...

represented

...

by

...

the

...

Shapeclass.

...

To

...

create

...

an

...

AutoShape:

...

  1. Return

...

  1. a

...

  1. Shapes

...

  1. collection.

...

  1. Code Block
    ExcelApplication xla = new ExcelApplication();
    Workbook wb = xla.Create();
    Worksheet ws = wb.Worksheets[0];
    Shapes shps = ws.Shapes;

...

  1. Create a shape of a specified type and insert it at an anchor in the worksheet.

    Code Block
    Anchor anch = ws.CreateAnchor(0, 7, 0, 0);
    Shape shpHeart = shps.CreateShape(ShapeType.Heart, anch);

...

The

...

ShapeType

...

class

...

contains

...

the

...

Excel

...

AutoShapes

...

supported

...

by

...

ExcelWriter.

...

The

...

specified

...

anchor

...

represents

...

the

...

position

...

of

...

the

...

top-left

...

corner

...

of

...

the

...

shape

...

in

...

the

...

worksheet.

...