找回密码
 立即注册

QQ登录

只需一步,快速开始

michael

银牌会员

22

主题

57

帖子

3974

积分

银牌会员

积分
3974

活字格认证

michael
银牌会员   /  发表于:2012-1-4 21:41  /   查看:5426  /  回复:3
如题
比如一个单元格设置成doublecelltype类型 想设置该单元格默认值为0.000 该如何实现

3 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2012-1-5 10:36:00
沙发

回复 1# michael 的帖子

michael 你好,可以通过继承 doublecelltype 实现自定义单元格类型实现,请参考代码:

  1.    public partial class WebForm1 : System.Web.UI.Page
  2.     {
  3.         protected void Page_Load(object sender, EventArgs e)
  4.         {
  5.             MyCellType test = new MyCellType();
  6.             this.FpSpread1.ActiveSheetView.Columns[0].CellType = test;
  7.         }
  8.     }
  9.     [Serializable]
  10.     public class MyCellType:FarPoint.Web.Spread.DoubleCellType
  11.     {
  12.         public override Control PaintCell(string id, TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)
  13.         {
  14.             if (value == null)
  15.             {
  16.                 value = "0.000";
  17.             }
  18.             return base.PaintCell(id, parent, style, margin, value, upperLevel);
  19.         }
  20.     }
复制代码
回复 使用道具 举报
michael
银牌会员   /  发表于:2012-1-10 19:58:00
板凳
我按照上述方式写的 但是发现几个问题
1.PaintCell方法的返回值不是Control而是void 不知道是不是和版本有关 我用的是4.0
2.按照
if (value == null){ value = "0.000"; }
这种方法添加到重写方法里 但是使用的时候没起作用
麻烦能不能做个demon我参考下 谢谢了
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-1-11 09:31:00
地板
michael 你好,
PaintCell 方法提供了两种重载,返回值分别为 void 和 control 。下面是我制作的 Demo:
编译环境:vs2008 + Spread for ASP.NET 4.0
Demo下载: Spread4.0.rar (1.86 MB, 下载次数: 268)

png

png
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部