我试图在一个excel表中导出2个表数据。 [英] am trying to export 2 tables data in one excel sheet.

查看:62
本文介绍了我试图在一个excel表中导出2个表数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图在一张excel表中导出2个表数据。



但是它只导出excelsheet中的第一个表数据。



 SqlDataAdapter dscmd2 =  new  SqlDataAdapter(  SELECT * FROM DriveInfo; SELECT * FROM NetworkInfo,conn); 
dscmd2.TableMappings.Add( DriveInfo);
dscmd2.TableMappings.Add( Table1 NetworkInfo);
DataSet ds2 = new DataSet();
dscmd2.Fill(ds2);

for (i = 0 ; i < = ds2.Tables [ 0 ]。Rows.Count - 1 ; i ++)
{
for (j = 0 ; j < = ds2.Tables [ 0 ]。Columns.Count - 1 ; j ++)
{
// data = ds.Tables [0] .Columns [j] .ColumnName.ToString();

data = ds2.Tables [ 0 ]。行[i ] .ItemArray [j]的的ToString();
// xlWorkSheet.Cells [i + 3,j + 1] = data;
xlWorkSheet2.Cells [i + 3 ,j + 1 ] = data;
}
}





谢谢

sam.198979

解决方案

参考:

如何使用c#

[ ^ ]

Hi,

am trying to export 2 tables data in one excel sheet.

but it's exporting only 1st table data in excelsheet.

SqlDataAdapter dscmd2 = new SqlDataAdapter("SELECT * FROM DriveInfo; SELECT * FROM NetworkInfo", conn);
            dscmd2.TableMappings.Add("Table", "DriveInfo");
            dscmd2.TableMappings.Add("Table1", "NetworkInfo");
            DataSet ds2 = new DataSet();
            dscmd2.Fill(ds2);

            for (i = 0; i <= ds2.Tables[0].Rows.Count - 1; i++)
            {
                for (j = 0; j <= ds2.Tables[0].Columns.Count - 1; j++)
                {
                    //data = ds.Tables[0].Columns[j].ColumnName.ToString();

                    data = ds2.Tables[0].Rows[i].ItemArray[j].ToString();
                    //xlWorkSheet.Cells[i + 3, j + 1] = data;
                    xlWorkSheet2.Cells[i + 3, j + 1] = data;
                }
            }



Thanks
sam.198979

解决方案

Refer:
How to export multiple tables in dataset to multiple sheets in excel using c#
[^]


这篇关于我试图在一个excel表中导出2个表数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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