如何将公式sum()应用于单元格 [英] how to apply formula sum() to a cell

查看:128
本文介绍了如何将公式sum()应用于单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我正在使用Vs 2008,C#,asp.net。

我有一个数据网格,我正在导出要擅长。

我想用一个单元格(D1:D5)将公式应用到一个单元格中使用C#



如何做到这一点?



提前致谢

george nt

Hi friends,

I am using Vs 2008,C#,asp.net.
I have a datagrid and i am exporting to excel.
I want to apply Sum(D1:D5)formula to a cell using C#

how to do this?

Thanks in advance
george n t

推荐答案

您需要使用Microsoft。 Office.Interop.Excel.dll或 EPPlus 执行此操作..



看看这些链接,你会得到一些想法。

i前一个月有相同的要求..我曾经使用过EPPlus ..它工作正常..



http://epplus.codeplex.com/discussions/250690 [ ^ ]



HTTP:// STA ckoverflow.com/questions/5512084/excel-interop-and-formula-range/5512369#5512369 [ ^ ]



http://stackoverflow.com/questions/8878896/adding-formula-to-excel -with-c-sharp-the-formula-shown [ ^ ]
You need to use Microsoft.Office.Interop.Excel.dll or EPPlus for performing this..

have a look on these links you will get some idea.
i had the same requirement some month before.. i had used EPPlus.. it works fine..

http://epplus.codeplex.com/discussions/250690[^]

http://stackoverflow.com/questions/5512084/excel-interop-and-formula-range/5512369#5512369[^]

http://stackoverflow.com/questions/8878896/adding-formula-to-excel-with-c-sharp-making-the-formula-shown[^]


在GridView中设置ShowFooter =True



Set the ShowFooter="True" in GridView

double dTotal = new double[1, dsTest.Tables[0].Columns.Count];
       for (int p = 0; p <= dsTest.Tables[0].Rows.Count - 1; p++)
       {
           for (int c = 1; c <= dsTest.Tables[0].Columns.Count - 2; c++)
           {
               dTotal[0, c] = dTotal[0, c] + Convert.ToDouble(dsTest.Tables[0].Rows[p][c]);
               GridView.FooterRow.Cells[(c+1)].Text = dTotal[0, c].ToString())
           }
   
        GridView.FooterRow.Cells[1].Text = "Total ";
       }





这是示例代码,您可以使用foreach语句修改它以获得更好的性能。



it's the sample code you can modify it with foreach statements for better performance.

这篇关于如何将公式sum()应用于单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆