C#在excel中添加超链接
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中添加超链接的更多相关文章
- Excel中添加并使用宏实现批量更新数据
一.状况描述 当我们需要后台更新大量数据的时候,可以使用该功能.二.解決方案 (1)新建一个Excel文件,并另存为启用宏的Excel工作簿,扩展名为.xlsm. (2)在Excel ...
- 使用OPEN XML SDK 读取EXCEL中的超链接Hyperlink
使用OPEN XML SDK 读取EXCEL中的超链接Hyperlink 原理 先创建一个包括全部EXCEL单元格中超链接Hyperlink数据的表,再定位单元格通过列头(如A1,B1)获取超链接信息 ...
- C#/VB.NET对EXCEL图片添加超链接
在日常工作中,在编辑文档时,为了方便自己或者Boss能够实时查看到需要的网页或者文档是,需要对在Excel中输入的相关文字进行超链接,那么对于一些在Excel中插入的图片我们该怎么实现超链接呢,下面给 ...
- django web 中添加超链接
django web 中添加不传参的超链接的方法如下: html: 在web中的超链接中加入一下url <a href="{% url 'app_name.views.url_func ...
- Java 在PDF 中添加超链接
对特定元素添加超链接后,用户可以通过点击被链接的元素来激活这些链接,通常在被链接的元素下带有下划线或者以不同的颜色显示来进行区分.按照使用对象的不同,链接又可以分为:文本超链接,图像超链接,E-mai ...
- Java 在Excel中添加分离型饼图、环形图
一.概述 Excel中可支持多种不同类型的图表,本文介绍如何绘制分离型饼图和环形图.其中,分离型饼图的绘制可分为整体分离型(即设置饼图分离程度)和局部分离(即设置点爆炸型值)两种情况.下面将以Java ...
- TextView 中添加超链接
在textView添加超链接,有两种方式,第一种通过HTML格式化你的网址,一种是设置autolink,让系统自动识别超链接,下面为大家介绍下这两种方法的实现 代码如下: 第一种 pu ...
- VUE-001-在表格单元格(el-table-column)中添加超链接访问
在进行前端网页开发时,通常列表数据我们使用table展示.那么如何在 el-table-column 单元格中使用超链接呢? 如下即是解决方式的一种: 仅需要将如下代码: <el-table-c ...
- excel 怎么添加超链接
1.只能对单元格添加超链接 2.如果要对单元格里面个别字做成超链接,可以使用图形工具,设置一个图形在里面,对这个图形做超链接 参考:https://jingyan.baidu.com/article/ ...
随机推荐
- dp题目列表
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- Python文件操作题
1.如何用Python删除一个文件 os.remove(filename)或者os.unlink(filename). 2.Python如何copy一个文件 shutil模块里有一个copyfile函 ...
- [mysql] Some non-transactional changed tables couldn't be rolled back
使用peewee的事务时,碰到一个郁闷的问题,事务似乎无效! 于是简化了下模型,写了简单的测试代码,发现问题,如题所示. 找到解答: https://github.com/etianen/django ...
- @ResponseBody返回不能正确接收
Spring-MVC中@ResponseBody返回Bean到前台接收这么一串代码,还套着HTML标签: The resource identified by this request is only ...
- Oracle 数据操作
查询及删除重复记录的SQL语句 1.查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 where Id in (select Id from 表 g ...
- Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- percona-toolkit 之 【pt-slave-delay】说明
摘要: 在主从复制的架构中,正常情况下主上操作的记录也会在从上进行操作,虽说是异步复制,但操作会“实时”的同步到从.比如在主上不小心误操作了,还没等反应过来从上也会马上执行误操作,后期只有通过二进制或 ...
- 数组里的数据绑定到dataset中
string [] an = {"a","b","c"};DataTable dt = new DataTable(); dt.Column ...
- codeforces 336 Div.2 B. Hamming Distance Sum
题目链接:http://codeforces.com/problemset/problem/608/B 题目意思:给出两个字符串 a 和 b,然后在b中找出跟 a 一样长度的连续子串,每一位进行求相减 ...
- linux 卸载软件
sudo apt-get autoremove --purge 后跟要卸载的软件名称, --purge表示要完全卸载.