c# 操作excle
添加引用 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的更多相关文章
- python 操作excle 之第三方库 openpyxl学习
目录 python 操作excle 之第三方库 openpyxl学习 安装 pip install openpyxl 英文文档链接 : 点击这里~ 1,定位excel 2,读取excle中的内容 3, ...
- Java操作Excle(基于Poi)
有一次有个同事问我会不会有java操作Excle,回答当然是不会了!感觉被嘲讽了,于是开始寻找度娘,找到个小例子,结果越写越有意思,最后就成就了这个工具类. import java.io.Buffer ...
- java基础以及操作Excle
今天把会经常用的几个集合的迭代方法又练习了一下,放在这里,经常复习! map集合迭代 /*** 迭代map[1]*/ for (Integer key : map.keySet()) {//迭代key ...
- python学习笔记:操作Excle
import xlwt #写excel import xlrd #读excel import xlutils #修改excel 一.写操作 1.写Excel import xlwt #写excel,导 ...
- Java POI操作Excle工具类
用到了jxl.jar和poi.jar 一些基本的操作Excel的操作方法: import java.io.File; import java.io.FileInputStream; import ja ...
- POI操作excle
将根目录下的poi-3.6-20091214.jar和Lib目录下三个通用包 commons-logging-1.1.jar junit-3.8.1.jar log4j-1.2.13.jar拷贝到项目 ...
- Python操作Excle
python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库.可从这里下载https://pypi.python.org/pypi.下面分别记录p ...
- c# 操作excle[转]
//引用Microsoft.Office.Interop.Excel.dll文件 //添加using using Microsoft.Office.Interop.Excel; using Excel ...
- php操作EXCLE(通过phpExcle实现读excel数据)
<?phprequire_once('/PHPExcel/Reader/Excel2007.php');$objReader = new PHPExcel_Reader_Excel2007;$P ...
随机推荐
- jquery中prop()和attr()的区别
相比attr,prop是1.6.1才新出来的,两者从中文意思理解,都是获取/设置属性的方法(attributes和properties).只是,window或document中使用.attr()方法在 ...
- Oracle学习笔记(七)
九.高级查询(分组,子查询)查询升级版: 需要用到三张表员工表: desc emp EMPNO 员工号 ENAME 员工姓名 JOB 员工职位 MGR 老板员工号 HIREDATE 员工入职日期 SA ...
- LCD相关基础知识
1.什么是LCD? (1)LCD(Liquid Crystal Display)俗称液晶.液晶是一种材料,液晶这种材料具有一种特点:可以在电信号的驱动下液晶分子进行旋转,旋转时会影响透光性, 因此我们 ...
- Duplicate Symbol链接错误的原因总结和解决方法[转]
from:http://www.cocoachina.com/bbs/read.php?tid=177492 duplicate symbol是一种常见的链接错误,不像编译错误那样可以直接定位到问题的 ...
- UISwitch的常见属性
1.onTintColor属性:设置ON一边的背景颜色,默认是绿色. 2.tintColor属性:设置OFF一边的背景颜色,默认是灰色,发现OFF背景颜色其实也是控件”边框“颜色. 3.thumbTi ...
- 3dsmax导入点云数据
http://blog.sina.com.cn/s/blog_a4f6aad50101ht99.html https://blog.csdn.net/yangziluomu/article/detai ...
- JVM GC 机制与性能优化
目录(?)[+] 1 背景介绍 与C/C++相比,JAVA并不要求我们去人为编写代码进行内存回收和垃圾清理.JAVA提供了垃圾回收器(garbage collector)来自动检测对象的作用域),可自 ...
- Oracle EBS客户化程序中格式化金额
在Oracle EBS系统中,随处可见金额的显示格式,通常情况下都具有千分位符,同时有一定位数的精度,让我们先来看看一些现成的例子 上面这些列子中的金额都显示了千分位符,同时具备以2位小数,难道 ...
- yum反查某个命令或so库在哪个包里面
yum whatprovides "*/XXX.so.1"
- Python 定制类 特殊方法
1.特殊方法 定义在class中 不需要直接调用,python的某些函数或操作符会自动的调用对应的特殊方法. 如定义了person类,使用print p 语句打印person类的实例时,就调用了特殊方 ...