C# Excel +++++ 读取其中的图片

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Tools.Excel;
using Excel;
using System.Reflection;
namespace excel
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建Application对象 
            Excel.Application xApp = new Excel.ApplicationClass();
            xApp.Visible = true;
            Excel.Workbook xBook = xApp.Workbooks._Open(@"D:\a.xls",
                      Missing.Value, Missing.Value, Missing.Value, Missing.Value
                    , Missing.Value, Missing.Value, Missing.Value, Missing.Value
                    , Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            //xBook=xApp.Workbooks.Add(Missing.Value);//新建文件的代码
          
            Excel.Worksheet xSheet = (Excel.Worksheet)xBook.Sheets[1];
            //读取数据,通过Range对象
            Excel.Range rng1 = xSheet.get_Range("B1", Type.Missing);
            //A1  B3 是行和列的标志
            Console.WriteLine(rng1.Value2);
            String a = (String )rng1.Value2;
            //读取,通过Range对象,但使用不同的接口得到Range
            Excel.Range rng2 = (Excel.Range)xSheet.Cells[3, 1];
            Console.WriteLine(rng2.Value2);
            String a1 = (String)rng2.Value2;
            //写入数据
            Excel.Range rng3 = xSheet.get_Range("C6", Missing.Value);
            rng3.Value2 = "Hello";
            rng3.Interior.ColorIndex = 6; //设置Range的背景色
            //保存方式三
            xBook.Save();
            xSheet = null;
            xBook = null;
            xApp.Quit(); //这一句是非常重要的,否则Excel对象不能从内存中退出 
            xApp = null;
        }
    }
}
++++++++++++++++++++++++++++++++++++
Code
++++++++++++++++++++++++++++++++++++++++

posted @ 2009-01-03 16:18  shuang  阅读(2165)  评论(0编辑  收藏  举报