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 ...
随机推荐
- 【转】C中的静态存储区和动态存储区
一.内存基本构成 可编程内存在基本上分为这样的几大部分:静态存储区.堆区和栈区.他们的功能不同,对他们使用方式也就不同. 静态存储区:内存在程序编译的时候就已经分配好,这块内存在程序的整个 ...
- md1
a b link to baidu 我不懂啊 这是什么意思 http://example.com/ 这里是一段代码' adsfasdf 你 你输得算好了 反正就这样吧,大概也值能这样了注 我想写一段引 ...
- Lucene的数值索引以及范围查询
对文本搜索引擎的倒排索引(数据结构和算法).评分系统.分词系统都清楚掌握之后,本人对数值索引和搜索一直有很大的兴趣,最近对Lucene对数值索引和范围搜索做了些学习,并将主要内容整理如下: 1. Lu ...
- 在一般处理程序清理cookie
清理cookie在ashx里面很奇怪,因为直接设置过期时间并不能成功,cookie还是会存在.所以需要添加一个同名的Cookie设置过期时间覆盖 HttpCookie cookie = null; / ...
- 杭州.Net 相关大公司,希望对大家有帮助
本人目前大四,还在实习.北京工作辞职后,打算回杭州看看.发现杭州的大公司相对北京好少啊,招.Net相关的公司就更少了... (我认为刚毕业生还是去大公司比较靠谱,一方面也是实力的体现)大学生,而且之前 ...
- .net core redis使用
整理下.net core的redis使用 可以分布式 Nuget安装 StackExchange.Redis using System; using System.Collections.Gener ...
- 如何让Syncthing始终使用同一个设备ID?
设备ID(device id)是Syncthing最重要的参数之一,所有节点的发现.连接等操作,全部是基于这个设备ID!对于已经建立起来的P2P网络,保持重要节点的设备ID唯一性是非常重要的!!!!那 ...
- 【ocp-12c】最新Oracle OCP-071考试题库(38题)
38.choose the best answer View the Exhibit and examine the data in the PROMOTIONS table. PROMO_BEGIN ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(35)
35.choose the best answer View the Exhibit and examine the description of the EMPLOYEES table. Evalu ...
- C# Winform下一个热插拔的MIS/MRP/ERP框架16(窗体基类场景2)
如果没有特别需求,和场景1一样只变更表名,主键字段,检测字段等名称,不需要写其它代码了. * 清单列表+单笔编辑/保存,适用于大多数基础资料管理以及简单的单据资料录入(当然,排版是要改一改的): * ...