日期:2014-05-16 浏览次数:20453 次
public static MemoryStream ExportToExcel(DataSet ds,ExcelType excelType,string header)
{
IWorkbook workbook = null;
if (excelType==ExcelType.Office2003)
{
workbook = new HSSFWorkbook();//2003
}
else
{
workbook = new XSSFWorkbook();//2007
}
#region 开始循环DS中的Table,DS中的每个表创建一个Sheet
for (int p = 0; p < ds.Tables.Count; p++)
{
#region 创建一个sheet
ISheet sheet = workbook.CreateSheet("sheet" + (p + 1));
//设置大标题行
int rowCount = 0;
//设置全局列宽和行高
sheet.DefaultColumnWidth = 14; //全局列宽
sheet.DefaultRowHeightInPoints = 15; //全局行高
//设置标题行数据
int a = 0;
IRow row1 = sheet.CreateRow(rowCount); //创建报表表头标题列
//for (int k = 0; k < ds.Tables[p].Columns.Count; k++)
//{ //将DataTable的列标题输出到Excel
// columnName = ds.Tables[p].Columns[k].ColumnName;
// row1.CreateCe