Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
In addition to [charts|Charts in ExcelApplication], 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.

h2. 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:
# Use the property Cell.Comment to return a Comment object.
{code:c#}
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create();
Worksheet ws = wb.Worksheets[0];

Cell cellB5 = ws.Cells["B5"];
Comment comm = cellB5.Comment;
{code}
# Add text to the comment.
{code:c#}comm.Text = "Figures for March are projected.";{code}
# Specify the author of the comment. {code:c#}comm.Author = "John Doe";{code}
# 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:c#}comm.Visible = true;{code}
# To modify the comment's display area, return its Shape object and set Shape properties, for example:
{code:c#}
Shape commShape = comm.Shape;
commShape.FillColor = oColor;
commShape.FitToText = true;
{code}

!comment.png!

h2. Creating a Picture


Pictures in a worksheet are stored in the Pictures collection. To add a picture to a worksheet:
# Return a Pictures collection.
{code:c#}
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create();
Worksheet ws = wb.Worksheets[0];
Pictures pics = ws.Pictures;
{code}
# 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:c#}
string imgPath = @"c:\images\owlogo.jpg";
Anchor anch = ws.CreateAnchor(0, 7, 0, 0);
Picture pic = pics.CreatePicture(imgPath, anch);
{code}
# To modify the size, position, or formatting of a Picture,  return its Shape object and set Shape properties, for example:
{code:c#}
Shape picShape = pic.Shape;
picShape.Rotation = 45;
{code}

h2. Creating an AutoShape


Excel's ready-made AutoShapes are represented by the Shapeclass.  To create an AutoShape:
# Return a Shapes collection.
{code:c#}
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create();
Worksheet ws = wb.Worksheets[0];
Shapes shps = ws.Shapes;
{code}
# Create a shape of a specified type and insert it at an anchor in the  worksheet.
{code:c#}
Anchor anch = ws.CreateAnchor(0, 7, 0, 0);
Shape shpHeart = shps.CreateShape(ShapeType.Heart, anch);{code}
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.
{scrollbar}