遇到个不好解决的问题 请大家都来帮忙啊 谢谢!!! 怎么用Excel输出报表、图表麻烦一下 带下代码..... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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");// } N年前写的代码lz自己看看也许还能用 数据库的问题 问个关于Ling非常简单,我却不明白的问题 两颗星了..散分,全部散光,大哥大姐小弟小妹们都进来坐一坐... 面对大批量网络访问的架构实现 RadioButtonList控件问题?????? 如何让同一个文件夹下的程序只运行一个实例(不完全是一个应用一个实例的的问题). 求助一个C#数据绑定和远程访问数据库的问题 vs08实时调试器 系统邮件服务如何关闭? Console.Out.WriteLine("asdf"); 请教一个函数问题! 如何获button的点击次数??
// 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");
// }
lz自己看看
也许还能用