遇到个不好解决的问题 请大家都来帮忙啊 谢谢!!!
怎么用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;
//
//
//xSt.get_Range(excel.Cells[4, 2],excel.Cells[rowIndex, 11]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
////
////绘制边框
////
//xSt.get_Range(excel.Cells[4, 2],excel.Cells[rowIndex, 11]).Borders.LineStyle = 1;
////xSt.get_Range(excel.Cells[4,2],excel.Cells[rowSum,colIndex]).Borders.LineStyle = 1;
////xSt.get_Range(excel.Cells[4,2],excel.Cells[rowSum,2]).Borders[XlBordersIndex.xlEdgeLeft].Weight = Excel.XlBorderWeight.xlThick;//设置左边线加粗
////xSt.get_Range(excel.Cells[4,2],excel.Cells[4,colIndex]).Borders[XlBordersIndex.xlEdgeTop].Weight = Excel.XlBorderWeight.xlThick;//设置上边线加粗
////xSt.get_Range(excel.Cells[4,colIndex],excel.Cells[rowSum,colIndex]).Borders[XlBordersIndex.xlEdgeRight].Weight = Excel.XlBorderWeight.xlThick;//设置右边线加粗
////xSt.get_Range(excel.Cells[rowSum,2],excel.Cells[rowSum,colIndex]).Borders[XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThick;//设置下边线加粗
////
////显示效果
////
//excel.Visible=true;
//
////xSt.Export(Server.MapPath( ". ")+ "\\ "+this.xlfile.Text+ ".xls ",SheetExportActionEnum.ssExportActionNone,Microsoft.Office.Interop.OWC.SheetExportFormat.ssExportHTML);
//xBk.SaveCopyAs(filepath);
//
//xBk.Close(false, null,null);
//
////excel.Quit();
//System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
//System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
////System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
//GC.Collect();
//xSt = null;
//xBk = null;
////excel = null;
//}
//catch(Exception ex)
//{
//if(xSt != null)
//{
//System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
//xSt = null;
//}
//if(xBk != null)
//{
//System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
//xBk = null;
//}
////if(excel != null)
////{
////excel.Quit();
////System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
////excel = null;
////}
//return ex.Message.Replace( " ' ", @ "\ ' ").Replace( "\r\n ", @ "\n ");
//}