问一下如何操作excel文档,我想在里面画线,绘制曲线图 最好能够来点具体例子,包括引用什么和需要声明什么,谢谢了先 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要引用excel.dll文件然后,using Excel;下面是操作excel的部分代码://操作excel文件Excel.Application excel = new Excel.ApplicationClass();excel.DefaultFilePath = System.Windows.Forms.Application.StartupPath+@"\file";Excel.Workbook workbook = excel.Workbooks.Add(Type.Missing);///画线 string cell = "A"+k.ToString()+":"+((char)(j+63)).ToString()+(i-1).ToString(); Excel.Range range = excel.get_Range(cell,Type.Missing); range.Select(); Excel.Borders borders=range.Borders; borders[Excel.XlBordersIndex.xlDiagonalDown].LineStyle = Excel.XlLineStyle.xlLineStyleNone; borders[Excel.XlBordersIndex.xlDiagonalUp].LineStyle = Excel.XlLineStyle.xlLineStyleNone; borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous; borders[Excel.XlBordersIndex.xlEdgeLeft].Weight = Excel.XlBorderWeight.xlThin; borders[Excel.XlBordersIndex.xlEdgeLeft].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous; borders[Excel.XlBordersIndex.xlEdgeTop].Weight = Excel.XlBorderWeight.xlThin; borders[Excel.XlBordersIndex.xlEdgeTop].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous; borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThin; borders[Excel.XlBordersIndex.xlEdgeBottom].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous; borders[Excel.XlBordersIndex.xlEdgeRight].Weight = Excel.XlBorderWeight.xlThin; borders[Excel.XlBordersIndex.xlEdgeRight].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlContinuous; borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight = Excel.XlBorderWeight.xlThin; borders[Excel.XlBordersIndex.xlInsideHorizontal].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous; borders[Excel.XlBordersIndex.xlInsideVertical].Weight = Excel.XlBorderWeight.xlThin; borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; ///画线结束//调整格式 range = excel.get_Range("A1:F1",Type.Missing); range.Select(); range.Font.Bold = true; range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; range.VerticalAlignment = Excel.XlVAlign.xlVAlignBottom; range.WrapText = false; range.Orientation = 0; range.AddIndent = false; range.ShrinkToFit = false; range.MergeCells = false; range.Merge(Type.Missing);//保存 workbook.SaveAs(name+"("+currentTime.ToLongDateString()+")",Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Excel.XlSaveConflictResolution.xlLocalSessionChanges,Type.Missing,Type.Missing,Type.Missing); workbook.Close(false,Type.Missing,Type.Missing); 问一下,你引用的是excel5.0还是11。0,还有i,j,k代表什么意思啊 地區:北京年限:2年技術:.Net BS开发工資:avg>>5K + 福利,人性化公司,不加班,工作开心,心情愉快。公司性質:汽车门户网站,国内汽车行业前三名。 PS: 透露点消息,我们公司正在招.net BS开发人员,如果哪位同仁想换工作,是一个不错的机会选择,加[email protected] 说应聘即可! GC.Collect(); sTemplate.CopyTo(filename,true); Microsoft.Office.Interop.Excel.Application excel; Microsoft.Office.Interop.Excel.Workbook workbook; Object oMissing=System.Reflection.Missing.Value; excel= new Microsoft.Office.Interop.Excel.Application(); workbook=excel.Workbooks.Open(filename,new object[]{3} ,new object[]{false},new object[]{5},new object[]{""},new object[]{""},new object[]{false},Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,null,new object[]{false},new object[]{true},Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel9795,new object[]{true},new object[]{true},new object[]{true}); //SQL="select AutoNO,User_SinrouMei,User_SinrouMei_Furigana,User_SinpuMei,User_SinpuMei_Furigana,User_MailAddress_PC,User_MailAddress_Moble,User_TEL_House,User_TEL_Moble,User_Yuubinbangou,User_Jyuusyo2,User_MarryDate,User_Time,User_LoginDate,User_Kekonsikibasyo,User_Hirouenbasyo,User_HirouenDate,User_hirouenTime from TBL_USER_INFO"; Sheets sheet=workbook.Worksheets; Worksheet worksheet=(Worksheet)sheet.get_Item(1); excel.Cells[1,1]="シリアルNO"; Microsoft.Office.Interop.Excel.Shape orgChart=worksheet.Shapes.AddLine(54, 33, 162, 33); Microsoft.Office.Interop.Excel.Shape orgChart1=worksheet.Shapes.AddLine(189, 199, 274, 199); orgChart.Line.Weight=2; orgChart.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; orgChart.Line.Style =Microsoft.Office.Core.MsoLineStyle.msoLineSingle; orgChart.Line.BeginArrowheadStyle = Microsoft.Office.Core.MsoArrowheadStyle.msoArrowheadOval; orgChart.Line.EndArrowheadStyle = Microsoft.Office.Core.MsoArrowheadStyle.msoArrowheadOval; orgChart.Line.BeginArrowheadWidth = Microsoft.Office.Core.MsoArrowheadWidth.msoArrowheadWidthMedium; orgChart.Line.BeginArrowheadLength = Microsoft.Office.Core.MsoArrowheadLength.msoArrowheadLengthMedium; orgChart.Line.EndArrowheadWidth = Microsoft.Office.Core.MsoArrowheadWidth.msoArrowheadWidthMedium; orgChart.Line.EndArrowheadLength = Microsoft.Office.Core.MsoArrowheadLength.msoArrowheadLengthMedium; orgChart.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; Microsoft.Office.Interop.Excel.Shape orgChart2=worksheet.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 116, 44, 36, 10);我的解决方法,以后可能会用的^_^ ps:使用的是excel2003 引用excel11.0 为什么调用findwindow说在以下方法或属性之间的调用不明确? 【初学者求教】如何拼接二进制,得到整数值。 如何让打开的窗口都是满屏幕的窗口 关于List<T>和Dictionary<K,V>的问题 js 可以创建DataSet吗 2.0 Sqldatasource问题, 应选择怎样的图书来学习C# 2.0? 高手请进,可惜我没分了~~帮我的我会记住,下次一定给分!~ 请问:想在程序里执行一个应用程序,我启动个进程可以吗? 虚心请教 怎么在TabControl控件的tabpage上加个自己画的小图标?(顺便散分!!) 新手对c#中委托的问题
然后,using Excel;
下面是操作excel的部分代码:
//操作excel文件
Excel.Application excel = new Excel.ApplicationClass();
excel.DefaultFilePath = System.Windows.Forms.Application.StartupPath+@"\file";
Excel.Workbook workbook = excel.Workbooks.Add(Type.Missing);
///画线
string cell = "A"+k.ToString()+":"+((char)(j+63)).ToString()+(i-1).ToString();
Excel.Range range = excel.get_Range(cell,Type.Missing);
range.Select();
Excel.Borders borders=range.Borders;
borders[Excel.XlBordersIndex.xlDiagonalDown].LineStyle = Excel.XlLineStyle.xlLineStyleNone;
borders[Excel.XlBordersIndex.xlDiagonalUp].LineStyle = Excel.XlLineStyle.xlLineStyleNone; borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeLeft].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeLeft].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeTop].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeTop].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeBottom].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeRight].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeRight].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlInsideHorizontal].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic; borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlInsideVertical].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic;
///画线结束
//调整格式
range = excel.get_Range("A1:F1",Type.Missing);
range.Select();
range.Font.Bold = true;
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
range.VerticalAlignment = Excel.XlVAlign.xlVAlignBottom;
range.WrapText = false;
range.Orientation = 0;
range.AddIndent = false;
range.ShrinkToFit = false;
range.MergeCells = false;
range.Merge(Type.Missing);
//保存
workbook.SaveAs(name+"("+currentTime.ToLongDateString()+")",Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Excel.XlSaveConflictResolution.xlLocalSessionChanges,Type.Missing,Type.Missing,Type.Missing);
workbook.Close(false,Type.Missing,Type.Missing);
年限:2年
技術:.Net BS开发
工資:avg>>5K + 福利,人性化公司,不加班,工作开心,心情愉快。
公司性質:汽车门户网站,国内汽车行业前三名。 PS: 透露点消息,我们公司正在招.net BS开发人员,如果哪位同仁想换工作,是一个不错的机会选择,加[email protected] 说应聘即可!
sTemplate.CopyTo(filename,true);
Microsoft.Office.Interop.Excel.Application excel;
Microsoft.Office.Interop.Excel.Workbook workbook;
Object oMissing=System.Reflection.Missing.Value;
excel= new Microsoft.Office.Interop.Excel.Application();
workbook=excel.Workbooks.Open(filename,new object[]{3} ,new object[]{false},new object[]{5},new object[]{""},new object[]{""},new object[]{false},Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,null,new object[]{false},new object[]{true},Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel9795,new object[]{true},new object[]{true},new object[]{true});
//SQL="select AutoNO,User_SinrouMei,User_SinrouMei_Furigana,User_SinpuMei,User_SinpuMei_Furigana,User_MailAddress_PC,User_MailAddress_Moble,User_TEL_House,User_TEL_Moble,User_Yuubinbangou,User_Jyuusyo2,User_MarryDate,User_Time,User_LoginDate,User_Kekonsikibasyo,User_Hirouenbasyo,User_HirouenDate,User_hirouenTime from TBL_USER_INFO"; Sheets sheet=workbook.Worksheets;
Worksheet worksheet=(Worksheet)sheet.get_Item(1);
excel.Cells[1,1]="シリアルNO";
Microsoft.Office.Interop.Excel.Shape orgChart=worksheet.Shapes.AddLine(54, 33, 162, 33);
Microsoft.Office.Interop.Excel.Shape orgChart1=worksheet.Shapes.AddLine(189, 199, 274, 199);
orgChart.Line.Weight=2;
orgChart.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
orgChart.Line.Style =Microsoft.Office.Core.MsoLineStyle.msoLineSingle;
orgChart.Line.BeginArrowheadStyle = Microsoft.Office.Core.MsoArrowheadStyle.msoArrowheadOval;
orgChart.Line.EndArrowheadStyle = Microsoft.Office.Core.MsoArrowheadStyle.msoArrowheadOval;
orgChart.Line.BeginArrowheadWidth = Microsoft.Office.Core.MsoArrowheadWidth.msoArrowheadWidthMedium;
orgChart.Line.BeginArrowheadLength = Microsoft.Office.Core.MsoArrowheadLength.msoArrowheadLengthMedium;
orgChart.Line.EndArrowheadWidth = Microsoft.Office.Core.MsoArrowheadWidth.msoArrowheadWidthMedium;
orgChart.Line.EndArrowheadLength = Microsoft.Office.Core.MsoArrowheadLength.msoArrowheadLengthMedium;
orgChart.Line.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
Microsoft.Office.Interop.Excel.Shape orgChart2=worksheet.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 116, 44, 36, 10);
我的解决方法,以后可能会用的^_^