各位兄弟好!
现在一问题如下:
比如在一个DataTable中有如下的结构及数据:
ItemCode  Location     Quantity
A           1F         3
A           2F         3
A           3F         8
A           4F         5
B           5F         4
B           6F         5
B           7F         6
B           8F         7
C           9D         1
C           2D         5
C           5E         6
C           7K         5
C           6P         7假设有三列这样的数据,其中ItemCode是按组来分的,相同的ItemCode可能有不同的Location,并且对应相应的数量(Quantity),我现在想用C#把这个数据表导出为Excel,在每个相同的货品下,得出一个总计,例如A货品共有19个,我想用直接通过判断数据表的方法判断某一个货品是否已到最后一个,例如A产品之后第五行是B产品,请问该怎样编程实现

解决方案 »

  1.   

    首先应该在没有保存到Excel之前完成计算等操作 存至数组等对象里面,然后在导出至Excel
      

  2.   

    你算下每种货物的Location  数量!
      

  3.   

    分级汇总合计。用sql语句实现
    select ItemCode,Location,quantity from 
    (
    select ItemCode,Location,quantity=sum(quantity),s1=0,s2=ItemCode,s3=0 from tt group by ItemCode,Location
    union all
    select ItemCode+'合计','',quantity=sum(quantity),s1=0,s2=ItemCode,s3=1 from tt group by ItemCode
    union all
    select '总计','',quantity=sum(quantity),s1=1,s2='',s3=1 from tt
    ) a order by s1,s2,s3
      

  4.   

    动态拼datatable,拼完之后,再加到excel里