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的更多相关文章

  1. 浅谈Excel开发:十 Excel 开发中与线程相关的若干问题

    采用VSTO或者Shared Add-in等技术开发Excel插件,其实是在与Excel提供的API在打交道,Excel本身的组件大多数都是COM组件,也就是说通过Excel PIA来与COM进行交互 ...

  2. C#变成数据导入Excel和导出Excel

    excel 基础 •整个excel 表格叫工作表:workbook:工作表包含的叫页:sheet:行:row:单元格:cell. •excel 中的电话号码问题,看起来像数字的字符串以半角单引号开头就 ...

  3. ASP.NET 導入Excel

    常常碰到這種需求,為了避免自己每次寫Code都要東翻西找Sample,乾脆丟上來當備份 此外,也為了方便網路上的大大們Copy Paste方便,小弟已經順便標示要複製程式碼的起始結束位置 在歡樂的貼程 ...

  4. C# Note38: Export data into Excel

    Microsoft.Office.Interop.Excel You have to have Excel installed. Add a reference to your project to ...

  5. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  6. .Net内存优化的几点经验

    以前从来没有想过.Net开发居然存在内存无法释放的问题,总是认为GC给我处理好了一切.现在GIS二次开发结合三维球开发,没有想到存在如此严重的内存增长,很快内存就不够用了,导致系统各种不稳定.球体和三 ...

  7. .NET & C# & ASP.NET

    .NET && C# && ASP.NET https://docs.microsoft.com/zh-cn/dotnet/ .NET Documentation We ...

  8. Microsoft.Office.Interop.Excel的用法以及利用Microsoft.Office.Interop.Excel将web页面转成PDF

    1.常见用法           using Microsoft.Office.Interop.Excel; 1)新建一个Excel ApplicationClass ExcelApp = New A ...

  9. 引用Microsoft.Office.Interop.Excel出现的问题

    引用Microsoft.Office.Interop.Excel出现的问题   转自:http://www.hccar.com/Content,2008,6,11,75.aspx,作者:方继祥 操作背 ...

随机推荐

  1. IE Firefox Safari 下 通过Div“隐藏”设置Accesskey的submit input

    实现效果: 进入页面后 通过快捷键  如Alt+C 调用相关的隐藏按钮 实现功能操作 正常情况下 设置 button => input type="submit" acces ...

  2. 如何通过wifi在android手机上安装调试应用

    如何通过wifi在android手机上安装调试应用 1. 首先还是要打开手机的usb调试选项,并通过usb线连接手机.2. 然后执行“adb tcpip 5555”,把adb从usb模式切换到tcpi ...

  3. Linux 命令 - head: 打印文件的开头部分

    命令格式 head [OPTION]... [FILE]... 命令参数 -c, --bytes=[-]K 显示每个文件的前 K 字节内容. -n, --lines=[-]K 显示每个文件的前 K 行 ...

  4. Git CMD - diff: Show changes between commits, commit and working tree, etc

    命令格式 git diff [options] [<commit>] [--] [<path>…​] git diff [options] --cached [<comm ...

  5. asp.net中用回车代替按钮事件

    第一步,先编写简单的页面代码,这里我们只需要一个按钮就足够了.当然,还有按钮事件. <html> <head> <title>测试绑定enter</title ...

  6. webBrowser1_DocumentCompleted不停被调用

    原文地址:http://blog.csdn.net/shuishenlong/article/details/7950576 关于DocumentCompleted事件,MSDN给出的解释是在文档加载 ...

  7. 删除织梦所有待审核稿件sql语句

    先提醒一下 archives是dedecms主表addonarticle 新闻信息表 在dede后台"系统->SQL命令行工具"运行下以命令即可(注意,运行后未审核的数据全被 ...

  8. mysql5.7版本免安装配置教程

    自己花了两天时间才搞清楚,希望对新手有一定帮助,有问题可以联系哦! mysql分为安装版本msi,免安装要压缩版本ZIP,下载网址:http://dev.mysql.com/downloads 免安装 ...

  9. LINQ(LINQ to Entities)

    LINQ to Entities 是 LINQ 中最吸引人的部分.它让你可以使用标准的 C# 对象与数据库的结构和数据打交道.使用 LINQ to Entities 时,LINQ 查询在后台转换为 S ...

  10. 转:Android 2.3 代码混淆proguard技术介绍

    ProGuard简介 ProGuard是一个SourceForge上非常知名的开源项目.官网网址是:http://proguard.sourceforge.net/. Java的字节码一般是非常容易反 ...