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

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

返回博客中心

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

 
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;
        }
复制代码

关于葡萄城

葡萄城软件是专业的软件开发技术和低代码平台提供商,以“赋能开发者”为使命,致力于通过表格控件、低代码和BI等各类软件开发工具和服务,一站式满足开发者需求,帮助企业提升开发效率并创新开发模式。葡萄城开发技术始于1980年,40余年来始终聚焦软件开发技术,有深厚的技术积累和丰富的产品线。是业界能够同时赋能软件开发和低代码开发的企业。凭借过硬的产品能力、活跃的用户社区和丰富的伙伴生态,与超过3000家合作伙伴紧密合作,产品广泛应用于信息和软件服务、制造、交通运输、建筑、金融、能源、教育、公共管理等支柱产业。