问题描述:使用 Spread制作交叉报表时,需要在单元格中画对角线实现复合表头的功能。
问题解答:可以使用GetCellRectangle方法来获取单元格所在矩形,进而绘制线。
关键代码:
- ///<summary>
- ///通过计算单元格的长度和宽度来计算 LineShape 的起始位置和角度
- ///</summary>
- ///<param name="startRowIndex">起始行</param>
- ///<param name="startColIndex">起始列</param>
- ///<param name="endRowIndex">结束行</param>
- ///<param name="endColIndex">结束列</param>
- ///<returns>返回 LineShape 所在矩形</returns>
- private Rectangle CaculateRectangle(int startRowIndex, int startColIndex, int endRowIndex, int endColIndex)
- {
- float height = 0;
- float width = 0;
- for (int i = startRowIndex; i <= endRowIndex; i++)
- {
- height += this.fpSpread1.Sheets[0].Rows[i].Height;
- }
- for (int i = startColIndex; i <= endColIndex; i++)
- {
- width += this.fpSpread1.Sheets[0].Columns[i].Width;
- }
- Rectangle cellRec = this.fpSpread1.GetCellRectangle(0, 0, startRowIndex, startColIndex);
- Point startPositoin = new Point(cellRec.Left - (int)this.fpSpread1.Sheets[0].SheetCorner.Columns[0].Width, cellRec.Top - (int)this.fpSpread1.Sheets[0].SheetCorner.Rows[0].Height);
- Rectangle rec = newRectangle(startPositoin, newSize((int)width, (int)height));
- return rec;
- }
复制代码
效果截图:
示例下载:点击下载 |