csharp excel interop programming
string fileName = "c:\\a.xlsx";
var application = new Application();
application.Visible = true;
var workbook = application.Workbooks.Open(fileName);
var worksheet = workbook.Worksheets[] as Microsoft.Office.Interop.Excel.Worksheet;
//var worksheet = workbook.Worksheets.Add(Type.Missing,Type.Missing,Type.Missing,Type.Missing) as Microsoft.Office.Interop.Excel.Worksheet; worksheet.Cells[,] = "Hello World!";
//Console.Read(); worksheet.Range["A1"].Value = "Hello Range"; worksheet.Range["A1:c3"].MergeCells=true; Range range = worksheet.Range["A1:A3"];
range.Name = "range1";
worksheet.Names.Add("range1", range); //worksheet.Range["range1"].Value;
//worksheet.Range["t1!range1"].Value //enum range
foreach (Microsoft.Office.Interop.Excel.Name name in worksheet.Names)
{
Console.WriteLine(name.RefersToRange.Cells.get_Address(true,true,Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1,Type.Missing));
Console.WriteLine(name.RefersToRange.Cells.Worksheet.Name);
Console.WriteLine(name.Name);
} //search
//set the cell color to red,which cell has the mached value
Range currentFind = null;
Range firstFind = null;
Range Fruits = worksheet.get_Range("A1", "J50");
currentFind = Fruits.Find("", Type.Missing,
XlFindLookIn.xlValues, XlLookAt.xlPart,
XlSearchOrder.xlByRows, XlSearchDirection.xlNext, false,
Type.Missing, Type.Missing);
while (currentFind != null)
{
// Keep track of the first range you find.
if (firstFind == null)
{
firstFind = currentFind;
} // If you didn't move to a new range, you are done.
else if (currentFind.get_Address(XlReferenceStyle.xlA1)
== firstFind.get_Address(XlReferenceStyle.xlA1))
{
break;
} currentFind.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
currentFind.Font.Bold = true; currentFind = Fruits.FindNext(currentFind);
}
//end search application.Quit();
csharp excel interop programming的更多相关文章
- 浅谈Excel开发:十 Excel 开发中与线程相关的若干问题
采用VSTO或者Shared Add-in等技术开发Excel插件,其实是在与Excel提供的API在打交道,Excel本身的组件大多数都是COM组件,也就是说通过Excel PIA来与COM进行交互 ...
- C#变成数据导入Excel和导出Excel
excel 基础 •整个excel 表格叫工作表:workbook:工作表包含的叫页:sheet:行:row:单元格:cell. •excel 中的电话号码问题,看起来像数字的字符串以半角单引号开头就 ...
- ASP.NET 導入Excel
常常碰到這種需求,為了避免自己每次寫Code都要東翻西找Sample,乾脆丟上來當備份 此外,也為了方便網路上的大大們Copy Paste方便,小弟已經順便標示要複製程式碼的起始結束位置 在歡樂的貼程 ...
- C# Note38: Export data into Excel
Microsoft.Office.Interop.Excel You have to have Excel installed. Add a reference to your project to ...
- (转) [it-ebooks]电子书列表
[it-ebooks]电子书列表 [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...
- .Net内存优化的几点经验
以前从来没有想过.Net开发居然存在内存无法释放的问题,总是认为GC给我处理好了一切.现在GIS二次开发结合三维球开发,没有想到存在如此严重的内存增长,很快内存就不够用了,导致系统各种不稳定.球体和三 ...
- .NET & C# & ASP.NET
.NET && C# && ASP.NET https://docs.microsoft.com/zh-cn/dotnet/ .NET Documentation We ...
- Microsoft.Office.Interop.Excel的用法以及利用Microsoft.Office.Interop.Excel将web页面转成PDF
1.常见用法 using Microsoft.Office.Interop.Excel; 1)新建一个Excel ApplicationClass ExcelApp = New A ...
- 引用Microsoft.Office.Interop.Excel出现的问题
引用Microsoft.Office.Interop.Excel出现的问题 转自:http://www.hccar.com/Content,2008,6,11,75.aspx,作者:方继祥 操作背 ...
随机推荐
- [转]IIS7.5 添加expires头 提高性能
本文转自:http://niutuku.com/tech/www/271454.shtml 对于页面中不经常变化的静态内容通过指定expires头,来进行浏览器端的缓存,减少每次访问时的请求. 原理: ...
- [未完成]关于DOM的总结
这样有什么好处吗? 一但这些东西变成了节点对象,意味着每一个节点对象都会有很多属性和行为提供出来. 如果div是一个对象,那么就可以针对这个对象调用其中的一些方法,对div操作. 这个操作可以包括,比 ...
- ActiveMQ(5.10.0) - 使用 JDBC 持久化消息
1. 编辑 ACTIVEMQ_HOME/conf/activemq.xml. <beans> <broker brokerName="localhost" per ...
- atomikos分布式事务的几个坑
atomikos几个坑:1.jta.properties:com.atomikos.icatch.output_dir=/datayes/atomikoscom.atomikos.icatch.log ...
- Linux命令(1):cd命令
1.作用:改变工作目录: 2.格式:cd [路径] 其中的路径为要改变的工作目录,可为相对路径或绝对路径 3.使用实例:[root@www uclinux]# cd /home/yourname/ ...
- Cocos2d-x开发中Ref内存管理
Ref类是Cocos2d-x根类,Cocos2d-x中的很多类都派生自它,例如,我们熟悉的节点类Node也派生自Ref.我们介绍Ref内存管理.内存引用计数Ref类设计来源于Cocos2d-iphon ...
- (转)C# 数据类型映射 (SQLite,MySQL,MSSQL,Oracle)
一.C# vs SQLite: C# SQLite 字段名 类型 库类型 GetFieldType(#) 转换 备注 F_BOOL bool BIT NOT NULL Boolean F_BOOL_N ...
- NodeJS服务器退出:完成任务,优雅退出
上一篇文章,我们通过一个简单的例子,学习了NodeJS中对客户端的请求(request)对象的解析和处理,整个文件共享的功能已经完成.但是,纵观整个过程,还有两个地方明显需要改进: 首先,不能共享完毕 ...
- css笔记——小图标文字对齐中级解决方案
出处:http://www.zhangxinxu.com/study/201603/icon-text-vertical-align.html css .icon { display: inline- ...
- 集成产品开发-IPD简介
内训IPD流程,听完后,觉的流程的力量很强大,可以高效的团队几千上万人的研发团队,来正确地为同一个目标前进.因为讲解者是从华为出来的,所以,相关的案例分析以及理解,都是以华为研发为模板来讲解的.这没错 ...