比如一个DataSet中有多个DataTable,现在要将这个DataSet数据集中的表导出一个Excel的Sheet文件中。
表1 :
ID 姓名 年龄
1 x1 15
2 x2 16
3 x3 17
表2 :
ID 种族 国籍
1 汉族 中国
2 回族 美国
导出到Excel的一个Sheet中 Sheet1
可是 出现了错列
结果如下:
1 x1 15
2 x2 16
3 x3 17
1 汉族 中国
2 回族 美国
请问是怎么回事?
表1 :
ID 姓名 年龄
1 x1 15
2 x2 16
3 x3 17
表2 :
ID 种族 国籍
1 汉族 中国
2 回族 美国
导出到Excel的一个Sheet中 Sheet1
可是 出现了错列
结果如下:
1 x1 15
2 x2 16
3 x3 17
1 汉族 中国
2 回族 美国
请问是怎么回事?
解决方案 »
- 站点如何禁止粘贴复制拖入等
- gridview 取值问题( GV.Rows[index].Cells[2].Text.ToString()取到的是空值)
- B/S结构中,有无通过扫码枪扫码的可能?
- 将FCKedit中的东西转换成静态HTML 大侠请进 在线等待
- 为什么按钮在<asp:Repeater>控件里时不能通过双击按钮添加事件?
- 在后台注册脚本里有‘<’ 到页面中却显示<
- asp页面提交数据到.net页面所遇到的怪问题!
- 关于<form>的问题
- 为我今天下午的精彩表现,为我多了一颗角,散分!!!
- 预览提示无权限?
- 求助:detalsview与gridview的问题
- 在下拉列表框中显示从calendar控件中选择的时间
protected void export(DataSet[] datasets)
{
//XlsDocument对象
AppLibrary.WriteExcel.XlsDocument doc = new AppLibrary.WriteExcel.XlsDocument();
//保存的文件名
doc.FileName = "Report.xls";
//工作簿
AppLibrary.WriteExcel.Worksheet sheet;
//单元格
AppLibrary.WriteExcel.Cells cells;
foreach (DataSet ds in datasets)
{
if (ds != null)
{
string sheetName = ds.DataSetName.ToString();
sheet = doc.Workbook.Worksheets.Add(sheetName); cells = sheet.Cells;
foreach (DataTable dt in ds.Tables)
{
if (dt.Rows.Count > 0)
{
for (int rowIndex = 1; rowIndex <= dt.Rows.Count; rowIndex++)
{
for (int colIndex = 1; colIndex <= dt.Columns.Count; colIndex++)
{
cells.Add(rowIndex, colIndex, dt.Rows[rowIndex-1][colIndex-1].ToString()); }
}
}
}
}
}
doc.Send();
Response.Flush();
Response.End();
}引用了一个类库文件AppLibrary
否则它会将多个表合成一个表。