最好能够来点具体例子,包括引用什么和需要声明什么,谢谢了先

解决方案 »

  1.   

    要引用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);
      

  2.   

    问一下,你引用的是excel5.0还是11。0,还有i,j,k代表什么意思啊
      

  3.   

    地區:北京
    年限:2年
    技術:.Net BS开发
    工資:avg>>5K + 福利,人性化公司,不加班,工作开心,心情愉快。
    公司性質:汽车门户网站,国内汽车行业前三名。 PS: 透露点消息,我们公司正在招.net BS开发人员,如果哪位同仁想换工作,是一个不错的机会选择,加[email protected] 说应聘即可!
      

  4.   

    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);
    我的解决方法,以后可能会用的^_^
      

  5.   

    ps:使用的是excel2003   引用excel11.0