日期:2014-05-20  浏览次数:20789 次

遇到个不好解决的问题 请大家都来帮忙啊 谢谢!!!
怎么用Excel输出报表、图表
麻烦一下   带下代码.....

------解决方案--------------------
Excel.Application excel = null;
// Excel._Workbook xBk = null;
// Excel._Worksheet xSt = null;
//
// bool failed = false;
//
// try
// {
// int rowIndex=4;
//
// if(excel == null)
// excel= new Excel.ApplicationClass();
//
// xBk = excel.Workbooks.Add(true);
//
// xSt = (Excel._Worksheet)xBk.ActiveSheet;
//
// //
// //取得标题
// //
// excel.Cells[4, 2] = "车型 ";
// xSt.get_Range(excel.Cells[4, 2],excel.Cells[4, 2]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 3] = "组号 ";
// xSt.get_Range(excel.Cells[4, 3],excel.Cells[4, 3]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 4] = "车牌号码 ";
// xSt.get_Range(excel.Cells[4, 4],excel.Cells[4, 4]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 5] = "教练 ";
// xSt.get_Range(excel.Cells[4, 5],excel.Cells[4, 5]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 6] = "座位号1 ";
// xSt.get_Range(excel.Cells[4, 6],excel.Cells[4, 6]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 7] = "座位号2 ";
// xSt.get_Range(excel.Cells[4, 7],excel.Cells[4, 7]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 8] = "座位号3 ";
// xSt.get_Range(excel.Cells[4, 8],excel.Cells[4, 8]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 9] = "座位号4 ";
// xSt.get_Range(excel.Cells[4, 9],excel.Cells[4, 9]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 10] = "座位号5 ";
// xSt.get_Range(excel.Cells[4, 10],excel.Cells[4, 10]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
// excel.Cells[4, 11] = "座位号6 ";
// xSt.get_Range(excel.Cells[4, 11],excel.Cells[4, 11]).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
//
// //
// //取得表格中的数据
// //
// foreach(DataRowView row in dv)
// {
// rowIndex ++;
// excel.Cells[rowIndex, 2] = row[9].ToString();
// excel.Cells[rowIndex, 3] = row[0].ToString();
// excel.Cells[rowIndex, 4] = row[1].ToString();
// excel.Cells[rowIndex, 5] = row[2].ToString();
// excel.Cells[rowIndex, 6] = row[3].ToString();
// excel.Cells[rowIndex, 7] = row[4].ToString();
// excel.Cells[rowIndex, 8] = row[5].ToString();
// excel.Cells[rowIndex, 9] = row[6].ToString();
// excel.Cells[rowIndex, 10] = row[7].ToString();
// excel.Cells[rowIndex, 11] = row[8].ToString();
// }
// //
// //设置选中的部分的颜色
// //
// // xSt.get_Range(excel.Cells[rowSum,colSum],excel.Cells[rowSum,colIndex]).Select();
// // xSt.get_Range(excel.Cells[rowSum,colSum],excel.Cells[rowSum,colIndex]).Interior.ColorIndex = 19;//设置为浅黄色,共计有56种
// //
// //取得整个报表的标题
// //
// excel.Cells[2, 2] = "科目三考试安排表 ";
// //
// //设置整个报表的标题格式
// //
// xSt.get_Range(excel.Cells[2, 2],excel.Cells[2, 2]).Font.Bold = true;
// xSt.get_Range(excel.Cells[2, 2],excel.Cells[2, 2]).Font.Size = 22;
// //
// //设置整个报表的标题为跨列居中
// //
// xSt.get_Range(excel.Cells[2, 2],excel.Cells[2, 11]).Select();
// xSt.get_Range(excel.Cells[2, 2],excel.Cells[2, 11]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenterAcrossSelection;