回复 13楼dkings的帖子
添加背景图后覆盖的为Spread 网格线(GridLine),这是Excel行为一致。
我们可以通过设置和单元格网格线一样的边框来解决这个问题,参考代码:
- Worksheet _worksheet = this.spread.ActiveSheet;
- ImageBrush im = new ImageBrush();
- im.ImageSource = new BitmapImage(new Uri("pack://application:,,,/WpfApplication2;component/untitled.png", UriKind.RelativeOrAbsolute));
- im.AlignmentX = AlignmentX.Right;
- im.AlignmentY = AlignmentY.Top;
- im.Stretch = Stretch.None;
- for (int i = 3; i <= 10; i++)
- {
- for (int j = 3; j <= 10; j++)
- {
- var rng = _worksheet.Cells[i, j];
- rng.Background = im;
- _worksheet.SetBorder(new CellRange(i, j, 1, 1), new BorderLine(_worksheet.GridLineColor, BorderLineStyle.Thin), SetBorderOptions.All);
- }
- }
- _worksheet.ShowGridLine = true;
复制代码 |