如何将三角形标记添加到SpreadsheetGear网格的任何单元格角? [英] How to add a triangle marker to any cell corner of SpreadsheetGear grid?

查看:219
本文介绍了如何将三角形标记添加到SpreadsheetGear网格的任何单元格角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个SpreadsheetGear网格特定的问题。我知道你可以给单元格添加评论,单元格会自动在右上角显示红色的三角形标记。但是我需要在任何单元格角落添加一个小三角形(不同的颜色)来表示特殊的东西。是否可以做到这一点?



UPATE:这是我根据Daniel的建议在单元格的任何一个角落添加了一个三角形的结果。

  public void AddTriangleShapeToCorner(IWorksheet工作表,int行,int col,CellCorners cellCorner)
{
const双倍宽度= 5,高度= 5;
double xOffset = 0,yOffset = 0;

IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;

if(cellCorner == CellCorners.TopRight || cellCorner == CellCorners.BottomRight)
{
col ++;
xOffset = width;
}
if(cellCorner == CellCorners.BottomLeft || cellCorner == CellCorners.BottomRight)
{
row ++;
yOffset = height;
}
double top = windowInfo.RowToPoints(row) - yOffset;
double left = windowInfo.ColumnToPoints(col) - xOffset;

IShape shape = worksheet.Shapes.AddShape(AutoShapeType.RightTriangle,left,top,width,height);
shape.Line.Visible = false; //左上角的线条不清晰,请将其关闭。
shape.Placement = Placement.Move; //使形状随着单元格移动。注意:它不适用于右上角和右下角。
if(cellCorner == CellCorners.TopLeft || cellCorner == CellCorners.TopRight)
shape.VerticalFlip = true;
if(cellCorner == CellCorners.TopRight || cellCorner == CellCorners.BottomRight)
shape.Horizo​​ntalFlip = true;


解决方案

您可以使用IShapes < a href =http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.7.0/SpreadsheetGear2012.Core~SpreadsheetGear.Shapes.IShapes~AddShape.html =nofollow> AddShape 方法。对于该类型,您可以使用AutoShapeType.RightTriangle。



以下是一个示例:

  private void AddTriangleShape(SpreadsheetGear.IWorksheet工作表,int iRow,int iCol)
{
SpreadsheetGear.IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;

//计算按钮的左边,顶边,宽度和高度
//将行和列坐标转换为点。使用小数$​​ b $ b //值来获取行列边界之间的坐标。
double left = windowInfo.ColumnToPoints(iCol);
double top = windowInfo.RowToPoints(iRow + 0.5);
double right = windowInfo.ColumnToPoints(iCol + 0.1);
double bottom = windowInfo.RowToPoints(iRow + 0.9);
double width =右 - 左;
double height = bottom - top;

worksheet.Shapes.AddShape(SpreadsheetGear.Shapes.AutoShapeType.RightTriangle,left,top,width,height);
}


This is a SpreadsheetGear Grid specific question. I know you can add a comment to a cell and the cell gets red triangle marker at the top right corner automatically. But I have a need to add a small triangle (different color) to any cell corner to indicate something special. Is it possible to do it?

UPATE: This is what I got for adding a triangle to any corner of the cell based on Daniel's suggestion.

    public void AddTriangleShapeToCorner(IWorksheet worksheet, int row, int col, CellCorners cellCorner)
    {
        const double width = 5, height = 5;
        double xOffset = 0, yOffset = 0;

        IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;

        if (cellCorner == CellCorners.TopRight || cellCorner == CellCorners.BottomRight)
        {
            col++;
            xOffset = width;
        }
        if (cellCorner == CellCorners.BottomLeft || cellCorner == CellCorners.BottomRight)
        {
            row++;
            yOffset = height;
        }
        double top = windowInfo.RowToPoints(row) - yOffset;
        double left = windowInfo.ColumnToPoints(col) - xOffset;

        IShape shape = worksheet.Shapes.AddShape(AutoShapeType.RightTriangle, left, top, width, height);
        shape.Line.Visible = false;         // line at top-left corner is not sharp, so turn it off.
        shape.Placement = Placement.Move;   // make the shape move with cell. NOTE: it doesn't work for top-right and bottom-right corners.
        if (cellCorner == CellCorners.TopLeft || cellCorner == CellCorners.TopRight)
            shape.VerticalFlip = true;
        if (cellCorner == CellCorners.TopRight || cellCorner == CellCorners.BottomRight)
            shape.HorizontalFlip = true;
    }

解决方案

You can use the IShapes AddShape method. For the type, you can use AutoShapeType.RightTriangle.

Here is an example:

private void AddTriangleShape(SpreadsheetGear.IWorksheet worksheet, int iRow, int iCol)
{
  SpreadsheetGear.IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;

  // Calculate the left, top, width and height of the button by 
  // converting row and column coordinates to points.  Use fractional 
  // values to get coordinates in between row and column boundaries.
  double left = windowInfo.ColumnToPoints(iCol);
  double top = windowInfo.RowToPoints(iRow + 0.5);
  double right = windowInfo.ColumnToPoints(iCol + 0.1);
  double bottom = windowInfo.RowToPoints(iRow + 0.9);
  double width = right - left;
  double height = bottom - top;

  worksheet.Shapes.AddShape(SpreadsheetGear.Shapes.AutoShapeType.RightTriangle, left, top, width, height);
}

这篇关于如何将三角形标记添加到SpreadsheetGear网格的任何单元格角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆