none
C# 操作excel 说明在哪能看到啊?! RRS feed

  • 问题

  • C# 操作excel 说明在哪能看到啊?!  我最近在研究 C# 里调用office 的excel 向excel里插入数据 而且调用 excel宏 

    我使用EXCEL2003 但是在excel表格里无法加入chart 图表不知道为什么而且弹出错误 请高人指教
    代码如下

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Office.Interop.Excel;
    using System.Reflection;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
               initialization();
               
                Application excel = new Application();
                excel.Visible = true;
               Workbook work= excel.Workbooks.Add(Missing.Value);
               Worksheet ws = (Worksheet)work.Sheets[1];
               ws.Cells[1, 1] = "姓名";
               ws.Cells[1,2]="成绩";
               int t = 2;
    
               foreach (student stu3 in studentlist)
               {
                   ((Worksheet)work.ActiveSheet).Cells[t, 1] = stu3.Name;
                   ((Worksheet)work.ActiveSheet).Cells[t++, 2] = stu3.Score;
               }
               //ws.Shapes.AddChart(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value).Select(Missing.Value);
               //work.ActiveChart.SetSourceData(((Worksheet)work.ActiveSheet).get_Range("A2", "B10"), Missing.Value);
               //work.ActiveChart.ChartType = XlChartType.xl3DColumn;
                Console.ReadLine();
                
            }
            static void initialization()
            {
                studentlist = new List<student>();
               
                for (int i = 0; i < 10; i++)
                {
                    Random r=new Random();
                    student stu = new student();
                    stu.Name = "第" + i.ToString() + "号学生";
                    stu.Score = r.Next(i * 4, 100);
                    studentlist.Add(stu);
                }
            }
            private static  List<student> studentlist;
    
        }
    }
    上面代码注释 部分就是 出现问题的部分  还有就是谁知道哪有 C# 使用OFFICE excel的 说明啊???详细一些的
    2009年9月25日 12:33

答案

全部回复