这是 SpreadsheetGear Grid 的特定问题。我知道您可以向单元格添加注释,单元格会自动在右上角获得红色三角形标记。但我需要在任何单元格角落添加一个小三角形(不同颜色)来指示一些特殊的东西。有可能做到吗?
更新:这是我根据丹尼尔的建议在单元格的任意角添加三角形得到的结果。
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;
}
您可以使用形状AddShape http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.7.0/SpreadsheetGear2012.Core~SpreadsheetGear.Shapes.IShapes~AddShape.html方法。对于类型,您可以使用 AutoShapeType.RightTriangle。
这是一个例子:
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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)