请问怎样将DataSet中的多个Tables导出为一个Excel表中的多个Sheet?

解决方案 »

  1.   

    //加载引用类
    imports exce;'//声明一个导出Excel函数
    public sub OutputExcel()
      
       dim app as new excel.application
       '//获取数据集
       dim dt as new datatable()
       dt=GetTable()'//获取数据函数自己一个即可
       dim  row as datarow
       dim rowsheet,colsheet as intgrate
       dim col as datacolumna
       dim xsheet as worksheet()
       dim xbook as workbooks()
       xsheet=app.workshewets("sheet1")
       xbook=app.workbooks().add
       
       rowsheet=0
       colsheet=1   for each col in dt.columns
         colsheet+=1
         app.cell(0,colsheet)=col.columname   
      next
      
       for each row int dt.rows
            rowsheet+=1
            colsheet=0
           for each col in dt.columns
               colsheet+=1
               app.cell(rowsheet,colsheet)=row(col.columna)
            next
       next   //设置导出样式....
       with app.websheet
          '这里代码自己写
       end with    app.excel.visible=trueend sub