添加引用  Microsoft.Office.Interop.Excel;

添加命名空间 using Excel = Microsoft.Office.Interop.Excel;

//创建接口变量------------------------------------------

_Workbook _xlWorkBook = null;
Worksheet _xlWorkSheet = null;
Excel.Application _xlApp = null;

//创建excle Application----------------------------------

_xlApp= new Excel.Application();
//_xlApp.DisplayAlerts = false; //设置报警窗口
_xlApp.Visible = true; //设置显示
// _xlApp.ScreenUpdating = false; //设置屏幕刷新

//创建workbook ----------------------------------------

//打开已存在的workbook  path是文件路径
_xlWorkBook = _xlApp.Workbooks.Open(path, System.Type.Missing, System.Type.Missing, System.Type.Missing,System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

//创建worksheet--------------------------------------------

//得到指定的sheet
//Excel.Worksheet xlsWorkSheet = (Worksheet)xlsWorkBook.Worksheets["2013年"];
_xlWorkSheet = (Worksheet)_xlWorkBook.Sheets["2013年"];//得到指定的sheet
//_xlWorkSheet =(Worksheet) _xlWorkBook.ActiveSheet;//得到当前活跃sheet

//获取所有sheet

Sheets xlsWorkSheets = _xlWorkBook.Worksheets;
foreach (var s in xlsWorkSheets)
{
Worksheet xlsWorkSheet = s as Worksheet;
string ss= xlsWorkSheet.Name;
}

//增加sheet页

// Worksheet workSheet = (Worksheet)_xlWorkBook.Worksheets.Add(System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

//创建Excel.Range----------------------------------------------------- 

             //获取单元格内容
var cell= (Range)_xlWorkSheet.Cells[1, 3];
var cellvalue = cell.Value.ToString();
string pathd = @"c:\wellname.txt";
_xlWorkSheet.Hyperlinks.Add(cell, pathd); //添加超链接
             //RowHeight   "1:1"表示第一行, "1:2"表示,第一行和第二行
((Excel.Range)_xlWorkSheet.Rows["1:1", System.Type.Missing]).RowHeight = 100;
//ColumnWidth "A:B"表示第一列和第二列, "A:A"表示第一列
((Excel.Range)_xlWorkSheet.Columns["A:B", System.Type.Missing]).ColumnWidth = 10;
Excel.Range excelRange = _xlWorkSheet.get_Range(_xlWorkSheet.Cells[10, 5], _xlWorkSheet.Cells[10, 5]);
excelRange.Select(); //选中区域
_xlApp.ActiveWindow.FreezePanes = true;//冻结字段
excelRange.Borders.LineStyle = 1; //区域边框线型
excelRange.Borders.get_Item(XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous;//区域顶部边框虚线
excelRange.Borders.get_Item(XlBordersIndex.xlEdgeBottom).Weight = Excel.XlBorderWeight.xlMedium; //单元格下边框线粗细
excelRange.Borders.get_Item(XlBordersIndex.xlEdgeBottom).ColorIndex = 3;//边框色彩
excelRange.Font.Size = 15;//字体大小
excelRange.Font.Underline = true;//下划线
excelRange.HorizontalAlignment = XlHAlign.xlHAlignCenter;//字体在单元格内的对其方式
excelRange.ColumnWidth = 15;//单元格的宽度
excelRange.Cells.Interior.Color = System.Drawing.Color.FromArgb(255, 204, 153).ToArgb();//单元格的背景色
//合并单元格
excelRange.Merge(excelRange.MergeCells);
_xlWorkSheet.get_Range("A15", "B15").Merge(_xlWorkSheet.get_Range("A15", "B15").MergeCells);

  

  

c# 操作excle的更多相关文章

  1. python 操作excle 之第三方库 openpyxl学习

    目录 python 操作excle 之第三方库 openpyxl学习 安装 pip install openpyxl 英文文档链接 : 点击这里~ 1,定位excel 2,读取excle中的内容 3, ...

  2. Java操作Excle(基于Poi)

    有一次有个同事问我会不会有java操作Excle,回答当然是不会了!感觉被嘲讽了,于是开始寻找度娘,找到个小例子,结果越写越有意思,最后就成就了这个工具类. import java.io.Buffer ...

  3. java基础以及操作Excle

    今天把会经常用的几个集合的迭代方法又练习了一下,放在这里,经常复习! map集合迭代 /*** 迭代map[1]*/ for (Integer key : map.keySet()) {//迭代key ...

  4. python学习笔记:操作Excle

    import xlwt #写excel import xlrd #读excel import xlutils #修改excel 一.写操作 1.写Excel import xlwt #写excel,导 ...

  5. Java POI操作Excle工具类

    用到了jxl.jar和poi.jar 一些基本的操作Excel的操作方法: import java.io.File; import java.io.FileInputStream; import ja ...

  6. POI操作excle

    将根目录下的poi-3.6-20091214.jar和Lib目录下三个通用包 commons-logging-1.1.jar junit-3.8.1.jar log4j-1.2.13.jar拷贝到项目 ...

  7. Python操作Excle

    python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库.可从这里下载https://pypi.python.org/pypi.下面分别记录p ...

  8. c# 操作excle[转]

    //引用Microsoft.Office.Interop.Excel.dll文件 //添加using using Microsoft.Office.Interop.Excel; using Excel ...

  9. php操作EXCLE(通过phpExcle实现读excel数据)

    <?phprequire_once('/PHPExcel/Reader/Excel2007.php');$objReader = new PHPExcel_Reader_Excel2007;$P ...

随机推荐

  1. 获取iPod library中的媒体文件

    [获取iPod library中的媒体文件] The Media Player framework provides facilities for playing movie, music, audi ...

  2. Android 4.0关于开机启动服务

    针对使用App应用管理强制停止的App,重启系统后不能收到开机启动, 需要运行一次后,在下次再启动时,才可以正确收到.

  3. Android JIN简单单步调试

    ADTr20已经比较完美支持NDK开发了.可以集成ndk编译,只需在项目右键Add Native Support,就能自动生成jni文件,并部署编译环境(注意这个过程是不可逆的,手动删除jni文件后, ...

  4. 一起学Angular

    最近想做一款跨平台(pc\app\pad)的东西玩玩,研究了许多技术: android.ios.H5.Bootrap.angular.angular2.ApiCloud.微信小程序 除android. ...

  5. Tomcat的windows10集群搭建(一台电脑同时运行多个tomcat配置方法)

    配置方法(好久不配置了,忘记了,今天还是总结下吧): 1.官网下载tomcat ,我下载了tomcat6.0和tomcat7.0(以便区分) 官网地址:http://tomcat.apache.org ...

  6. PHP(四)表单的基本处理

  7. 中心极限定理&&正态分布 随想

    0-前言 笔者本来周末约好朋友出去骑行,不料天公不作美!哎,闲来无事来到了实验室,本来打算看看<天天向上>,而这一期又实在不好看(偶像剧).只好来做做一些小实验,脑海里突然想到“正态分布“ ...

  8. postgresql 修改配置生效方法

    对于配置服务器,,太多时候我们在Linux中做的操作是,配置*.conf文件,然后重启服务.而很多服务都具有reload功能,而但是具体到某个配置,有时候直接说出需不需要重启服务而使得配置生效,这并不 ...

  9. TSQL--如何突破PRINT的8000大限

    相信很多DBA都喜欢干的一件事就是拼SQL语句,我也不例外,但是PRINT只能打印4000的Unicode string或8000的Non-unicode string, 这个蛋疼的限制会导致过长的s ...

  10. Tempdb--Snapshot

    The insert operation does not cause a row version to be generated because there is really no prvious ...