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,作者:方继祥 操作背 ...
随机推荐
- vb中的null.nothing.empty区别
以下内容源自互联网: 变量 A.B.C.D 分别等于 0."".Null. Empty. Nothing 的哪一个? Dim A Dim B As String Dim C As ...
- webView中支持input的file的选择和alert弹出
alert()弹出 input的file现选择(特别说明:不同的android版本弹出的样式不同,选择文件后自动上传) webView.setWebChromeClient(new WebChrome ...
- 【原创】 windows下开发软件推荐
1. 数据库查看器工具 navicat.exe
- Microsoft.SharePoint.Security的问题
请求“Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0 ...
- freeCodeCamp:GO BYBY GO!
千里之行,始于足下. 今天是2016年10月26日, 写前端代码有一年多了, 渐渐找到了一些方向, 知道该往哪里努力, 也慢慢开始总结自己的工作和学习. 希望在这里记录下的点点滴滴, 成为我日后学习的 ...
- JS定位PDF页码。
由于项目中的PDF文章段落标题有些是英文,对其翻译后需要定位到具体的页码. 查询相关资料及进行尝试后发现可以用如下方法可以实现 function gotoPage(page) { ...
- 每天一道LeetCode--342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- Linux命令(6):mv命令
1.作用: 为文件或目录改名或将文件由一个目录移入另一个目录中 2.格式: mv [选项] 源文件或目录 目标文件或目录 3.常见参数: 4.使用实例: [root@localhost ~]# mv ...
- iMAC——关闭自动弹出手机照片
有时当自己的iPhone手机插入一台iMAC电脑时,会自动弹出自己iPhone手机的照片. 这相当影响人的隐私等等,所以顺便将方法(参考网络的)小记一篇博客. 一.OS X 10.10以上用户解决办法 ...
- block的动态传值例子
/* 写一个block传值 ,让两个数进行相除和相乘,在运行时动态决定采用哪种计算方式 */ #import <Foundation/Foundation.h> int main(in ...