1.新建一个项目

2.给项目添加引用:Microsoft Excel 12.0 Object Library (2007版本)

using Excel = Microsoft.Office.Interop.Excel;

3.对excel的简单操作:如下代码“添加超链接”等。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel; namespace ExcelExample
{
class Program
{
static void Main(string[] args)
{
Excel.Application excelApp = new Excel.Application(); // Creates a new Excel Application
excelApp.Visible = true; // Makes Excel visible to the user. // The following line if uncommented adds a new workbook
//Excel.Workbook newWorkbook = excelApp.Workbooks.Add(); // The following code opens an existing workbook
string workbookPath = "F:\\11.xlsx"; // Add your own path here Excel.Workbook excelWorkbook = null; try
{
excelWorkbook = excelApp.Workbooks.Open(workbookPath, ,
false, , "", "", false, Excel.XlPlatform.xlWindows, "", true,
false, , true, false, false);
}
catch
{
//Create a new workbook if the existing workbook failed to open.
excelWorkbook = excelApp.Workbooks.Add();
} // The following gets the Worksheets collection
Excel.Sheets excelSheets = excelWorkbook.Worksheets; // The following gets Sheet1 for editing
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet); // The following gets cell A1 for editing
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "B1"); // The following sets cell A1's value to "Hi There"
excelCell.Value2 = "Hi There"; Excel.Worksheet excelWorksheet2 = (Excel.Worksheet)excelSheets.get_Item("Sheet2");
Excel.Range excelCell2 = (Excel.Range)excelWorksheet2.get_Range("A1", Type.Missing);
excelCell2.Value2 = "Hi Here"; // Add hyperlinks to the cell A1
//excelWorksheet.Hyperlinks.Add(excelCell,"http:\\www.baidu.com",Type.Missing,"baidu",Type.Missing); // Add hyperlinks from "sheet1 A1" to "sheet2 A1"
excelWorksheet.Hyperlinks.Add(excelCell, "#Sheet2!A1", Type.Missing, Type.Missing, Type.Missing); // Close the excel workbook
//excelWorkbook.Close(true,Type.Missing,Type.Missing); //Quit the excel app
//excelApp.Quit();
}
}
}

参考:

http://support.microsoft.com/kb/302084/zh-cn

http://www.codeproject.com/Articles/5123/Opening-and-Navigating-Excel-with-C

 

C#在excel中添加超链接的更多相关文章

  1. Excel中添加并使用宏实现批量更新数据

    一.状况描述    当我们需要后台更新大量数据的时候,可以使用该功能.二.解決方案    (1)新建一个Excel文件,并另存为启用宏的Excel工作簿,扩展名为.xlsm.    (2)在Excel ...

  2. 使用OPEN XML SDK 读取EXCEL中的超链接Hyperlink

    使用OPEN XML SDK 读取EXCEL中的超链接Hyperlink 原理 先创建一个包括全部EXCEL单元格中超链接Hyperlink数据的表,再定位单元格通过列头(如A1,B1)获取超链接信息 ...

  3. C#/VB.NET对EXCEL图片添加超链接

    在日常工作中,在编辑文档时,为了方便自己或者Boss能够实时查看到需要的网页或者文档是,需要对在Excel中输入的相关文字进行超链接,那么对于一些在Excel中插入的图片我们该怎么实现超链接呢,下面给 ...

  4. django web 中添加超链接

    django web 中添加不传参的超链接的方法如下: html: 在web中的超链接中加入一下url <a href="{% url 'app_name.views.url_func ...

  5. Java 在PDF 中添加超链接

    对特定元素添加超链接后,用户可以通过点击被链接的元素来激活这些链接,通常在被链接的元素下带有下划线或者以不同的颜色显示来进行区分.按照使用对象的不同,链接又可以分为:文本超链接,图像超链接,E-mai ...

  6. Java 在Excel中添加分离型饼图、环形图

    一.概述 Excel中可支持多种不同类型的图表,本文介绍如何绘制分离型饼图和环形图.其中,分离型饼图的绘制可分为整体分离型(即设置饼图分离程度)和局部分离(即设置点爆炸型值)两种情况.下面将以Java ...

  7. TextView 中添加超链接

    在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现   代码如下:    第一种    pu ...

  8. VUE-001-在表格单元格(el-table-column)中添加超链接访问

    在进行前端网页开发时,通常列表数据我们使用table展示.那么如何在 el-table-column 单元格中使用超链接呢? 如下即是解决方式的一种: 仅需要将如下代码: <el-table-c ...

  9. excel 怎么添加超链接

    1.只能对单元格添加超链接 2.如果要对单元格里面个别字做成超链接,可以使用图形工具,设置一个图形在里面,对这个图形做超链接 参考:https://jingyan.baidu.com/article/ ...

随机推荐

  1. 如何给ZenCart网站livezilla客服系统?

    大致步骤: 1 去官网下载livezilla

  2. django 1.7+ default_permissions

    由于做Caption要做权限设计.在核心类的设计的时候需要做好权限的基础设计.django 1.7+以后 django.db.modes新增特性 default_permissions,官方文档语焉不 ...

  3. Activity中UI框架基本概念

    Activity中UI框架基本概念 Activity 是应用程序的基本组成部分,提供了可视的界面,UI容器, 与用户进行交互: 具体Acitivity是怎么样显示这些事视图元素以及响应事件交互的. 一 ...

  4. 转:jquery向普通aspx页面发送ajax请求

    本文将介绍在ASP.NET中如何方便使用Ajax,第一种当然是使用jQuery的ajax,功能强大而且操作简单方便,第二种是使用.NET封装好的ScriptManager. $.ajax向普通页面发送 ...

  5. Zebra_Form Packages: Zebra_Form Controls Generic XSS_Clean Classes: Zebra_Form_Control Class: Zebra_Form_Control

    http://stefangabos.ro/wp-content/docs/Zebra_Form/Generic/Zebra_Form_Control.html#methodset_rule

  6. NFV技术中遇到的新名词

    NUMA topology:Non-Uniform Memory Access (NUMA) is a computer system architecture that is used with m ...

  7. devstack两次以上重装提高成功率的方法

    1) /opt/stack/requirements/ git reset --hard 2) rm -rf /usr/local/lib/python2.7/dist-packages/*

  8. iOS gcd dispatch使用注意,dispatch_syn可能产生的死锁

      我们在使用dispatch_sync 时可能会出现死锁,看下面的例子: import UIKit class ViewController: UIViewController { var seri ...

  9. cxGrid 速度

    在做AdoHelper实用程序的时候,我用了DevExpress的cxGrid控件.在此之前用的是dbgrid,考虑到不能把所有的数据都拉到本地,我用了动态生成的select top 500的命令.这 ...

  10. gtk+-3.21.4 static build step in windows XP

    In recent days the weather is very hot Unable to sleep properly Under the state of daze research gtk ...