zoukankan      html  css  js  c++  java
  • 竖表变横表(支持固定列)

    根据LoveCherry的竖变横方法改进而来(http://www.cnblogs.com/lovecherry/archive/2005/04/23/143819.html)

            public DataTable MakeData(DataTable dt,int iColumnSize,int[] iColumnID) //iColumnsize:重复列数 iColumnID 需要横向排列的列的序号数组
            {   
                
    int ColumnCount=iColumnID.Length;
                
    int totalRows=dt.Rows.Count;
                
    int itmp=dt.Rows.Count%iColumnSize; //行数
                int iRows; //行数
                if(itmp==0
                    iRows
    =dt.Rows.Count/iColumnSize; 
                
    else 
                    iRows
    =dt.Rows.Count/iColumnSize+1
                DataTable newdt
    =new DataTable(); 
                
    for(int i=0;i<iColumnSize;i++
                
    {  
                    
    for(int j=0;j<ColumnCount;j++)
                    
    {  string aa=dt.Columns[iColumnID[j]].ColumnName+i;
                        
    int bb=iColumnID[j];
                        DataColumn dc
    =new DataColumn(dt.Columns[iColumnID[j]].ColumnName+i,dt.Columns[iColumnID[j]].DataType); 
                    
                        newdt.Columns.Add(dc); 
                    }

                }
     
                
    for(int i=0;i<iRows;i++
                
    {         
                    DataRow dr
    =newdt.NewRow(); 
                    
    for(int j=0;j<iColumnSize;j++
                    

                        
    for(int k=0;k<ColumnCount;k++)
                        
    {
                            
    if((i+j*iColumnSize)<dt.Rows.Count) 
                            
    {  
                                
    string aa=dt.Columns[iColumnID[k]].ColumnName+j;
                                
    try
                                
    {
                                    dr[dt.Columns[iColumnID[k]].ColumnName
    +j]=dt.Rows[iRows*j+i][iColumnID[k]]; 
                                }

                                
    catch
                                
    {}
                            }

                        }

                    }
     
                    newdt.Rows.Add(dr);                 
                }
     
                
    return newdt; 
            }
     
  • 相关阅读:
    css背景颜色渐变效果
    manachar算法小结
    hdu--3068 最长回文串(manachar模板)
    ac自动机小结
    hdu--2896 病毒侵袭(ac自动机)
    hdu--1251 统计难题(字典树水题)
    hdu--1540 Tunnel Warfare(线段树+区间合并)
    poj--3667 Hotel(线段树+区间合并)
    hdu--3308 LCIS(线段树+区间合并)
    hdu--5023 A Corrupt Mayor's Performance Art(线段树+区间更新+位运算)
  • 原文地址:https://www.cnblogs.com/phiree/p/280518.html
Copyright © 2011-2022 走看看