Spread for ASP.NET 表格控件:设置导入 Excel 的边框

发布时间:2013/07/26 00:07 发布者:iceman

返回博客中心

论坛中有用户反馈 Spread 表格控件在导入 Excel 后,出现边框变粗的问题。由于 Spread 作为Html Table渲染到浏览器,所以边框会出现叠加效果。本文就将阐述如何设置边框使其与 Excel 相同:

Excel 原始效果如图:

image

导入 Spread 不做处理状态:

image

通过以下操作可以还原 Excel 边框效果,代码如下:

  1: //获取最后一个不为空的行例索引
  2: int rowCount = this.FpSpread1.Sheets[0].NonEmptyRowCount;
  3: int colCount = this.FpSpread1.Sheets[0].NonEmptyColumnCount;
  4: 
  5: //遍历设置 Cell 边框大小
  6: for (int i = 0; i < rowCount; i++)
  7: {
  8:     for (int j = 0; j < colCount; j++)
  9:     {
 10:         if (this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderStyleBottom == BorderStyle.Solid)
 11:         {
 12:             this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderSizeBottom = 1;
 13:         }
 14:         if (this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderStyleLeft == BorderStyle.Solid)
 15:         {
 16:             this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderSizeLeft = 1;
 17:         }
 18:         if (this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderStyleRight == BorderStyle.Solid)
 19:         {
 20:             this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderSizeRight = 1;
 21:         }
 22:         if (this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderStyleTop == BorderStyle.Solid)
 23:         {
 24:             this.FpSpread1.Sheets[0].Cells[i, j].Border.BorderSizeTop = 1;
 25:         }
 26:     }
 27: }

 

最终效果图:


image

VS2010 + C# + .NET 4.0 + Spread Studio .NET 7: 点击下载


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网