Spread for ASP.NET 使用拼接方法设置公式

发布时间:2012/11/14 00:11 发布者:葡萄城产品团队

返回博客中心

鉴于论坛中有很多用户提出如何在后台拼接公式,下面给出实现方法:

 
protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            FpSpread1.Sheets[0].ReferenceStyle = FarPoint.Web.Spread.Model.ReferenceStyle.R1C1;
            this.FpSpread1.ClientAutoCalculation = true;

            this.FpSpread1.Sheets[0].Cells[0, 2].Tag = "单价";
            this.FpSpread1.Sheets[0].Cells[1, 3].Tag = "数量";
            this.FpSpread1.Sheets[0].Cells[2, 3].Tag = "总金额";

            FarPoint.Web.Spread.Cell _unitPrice = this.FpSpread1.Sheets[0].GetCellFromTag(this.FpSpread1.Sheets[0].Cells[0, 0], "单价");
            FarPoint.Web.Spread.Cell _quantity = this.FpSpread1.Sheets[0].GetCellFromTag(this.FpSpread1.Sheets[0].Cells[0, 0], "数量");
            FarPoint.Web.Spread.Cell _toalPrice = this.FpSpread1.Sheets[0].GetCellFromTag(this.FpSpread1.Sheets[0].Cells[0, 0], "总金额");
            this.FpSpread1.Sheets[0].AllowUserFormulas = true;
            string formula = "PRODUCT(" + "R" + (_unitPrice.Row.Index + 1).ToString() + "C" + (_unitPrice.Column.Index + 1).ToString() + "," + "R" + (_quantity.Row.Index + 1).ToString() + "C" + (_quantity.Column.Index + 1).ToString() + ")";

            _toalPrice.Formula = formula;
        }
复制代码

关于葡萄城

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

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