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,作者:方继祥 操作背 ...
随机推荐
- CF Drazil and Factorial (打表)
Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- U-boot新手入门
U-boot新手入门 一.编译U-boot 二.U-boot命令详解 1.帮助命令 # help autoscr -run script from memory base -print or set ...
- C# Distinct方法的使用笔记
引自:http://blog.csdn.net/shaopengfei/article/details/36426763 从C# 3.0开始提供了Distinct方法,这对于集合的使用有了更为丰富的方 ...
- Linux C编程--打开和关闭流
以下函数用于打开和关闭一个流.#include <stdio.h>FILE * fopen (const char *pathname, const char *opentype);int ...
- Android Studio工程目录介绍
来自知乎: Android Studio工程目录结构 .gradle 是gradle运行以后生成的缓存文件夹. .idea 是android studio/Intellij IDEA工程打开以后生成的 ...
- DialogFragment
DialogFragment 从Android 3.0 (API level 11)开始引入,如果想在低于该版本的系统上使用,需用android.support.v4.app.DialogFragme ...
- 【SQL】关于存储过程调用过程中事务的点点滴滴
1.调用两个存储过程 ---------------------------------------------------------------- -- 表[dbo].[aaa_test]中[id ...
- Agile.Net 组件式开发平台 - 数据访问组件
Agile.DataAccess.dll 文件为系统平台数据访问支持库,基于FluentData扩展重写,提供高效的性能与风格简洁的API,支持多种主流数据库访问. 当前市面上的 ORM 框架,如 E ...
- sql中的触发器、视图、事务
·触发器(trigger) [触发器本质上还是一个存储过程,只不过不是用exe来调用执行,而是通过增删改数据库的操作] [触发器只对增.删.改有效] 触发器的格式 (instead of与for的区别 ...
- CSS 文字溢出时的自动隐藏
http://www.111cn.net/cssdiv/css/34050.htm 语法:overflow : visible | auto | hidden | scroll visible::不剪 ...