c#在excel中添加超链接示例分享
发布时间:2023-06-03 14:10:45
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, 0,
false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
false, 0, 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();
}
}
}


猜你喜欢
- C#实现的鼠标钩子,可以获取鼠标在屏幕中的坐标,记得要以管理员权限运行才行using System;using System.Collect
- JAVA用于开发图形界面应用的 SWING 组件包功能强大,使用方便。接下来我们就使用其写一个简单的图形界面小程序:加法计算器。第一步:首先
- Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序。这些服务可以在计
- 相同:1、LinkedBlockingQueue和ArrayBlockingQueue都实现了BlockingQueue接口;2、Linke
- optString方法会在对应的key中的值不存在的时候返回一个空字符串,但是getString会抛一个JSONException 。 /*
- 1. JVM 运行时数据区JVM运行时数据区可以分为元空间,堆,虚拟机栈,本地方法栈,程序计数器五大块。元空间(方法区):存放类模版对象,是
- 1 spring-retry是什么?以往我们在进行网络请求的时候,需要考虑网络异常的情况,本文就介绍了利用spring-retry,是spr
- XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便。对于XML本身的语法知识
- 背景:当我们有需求将HashMap转为Json格式的String时,切记不要使用HashMap的toString()方法,需要使用FastJ
- Java for循环打印菱形Java代码输出菱形的方法和思路有很多,在此分享一个稍带模块化拆分思想的解决方案,将需要输出的菱形拆分成8个模块
- 线上出现了如上的 crash,第一解决反应是在 show dialog 之前做个 isFinish 和 isDestroyed 判断,当我翻
- 前言当我们爱上lambda并且大范围使用它的时候,我想大家都会被lambda中的return语句狠狠地调戏过,所以今天我们需要一起来揭开la
- 下面是我自己收集整理的2017年Java岗位的面试题,可以用它来好好准备面试。一、Java基础1. String类为什么是final的。2.
- 不论你是否关注,Java Web应用都或多或少的使用了线程池来处理请求。线程池的实现细节可能会被忽视,但是有关于线程池的使用和调优迟早是需要
- 本文结合之前的动态创建fragment来进行一个实践,来实现用Fragment创建一个选项卡项目布局<LinearLayout xml
- 本文实例讲述了C#操作注册表的方法。分享给大家供大家参考,具体如下:下面我们就来用.NET下托管语言C#注册表操作,主要内容包括:注册表项的
- 本文实例为大家分享了C语言实现餐饮管理系统的具体代码,供大家参考,具体内容如下#include <stdio.h>#includ
- 这个功能一共有两部分组成,第一部分是窗体代码,另外的一部分是一个辅助方法。直接贴出代码,以供大家参考:using System;using
- 数据库表结构departmentemployee要求一现在的要求是输入 id 把 employee 表的对应员工数据查询出来,并且查询出该员
- 目录简介为什么使用protobuf定义.proto文件编译协议文件详解生成的文件Builders 和 Messages序列化和反序列化协议扩