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();
}
}
}
猜你喜欢
- 本文实例讲述了Java Swing中JDialog实现用户登陆UI。分享给大家供大家参考,具体如下:JDialog是一种对话框组件,它常常与
- C#获取远程图片,需要Form用户名和密码的Authorization认证using System;using System.Collect
- 本文实例为大家分享了swing登录注册界面展示的具体代码,供大家参考,具体内容如下开发环境:Eclipse Neon.3 Release (
- 概念二叉搜索树又称二叉排序树,它或者是一棵空树,或者是具有以下性质的二叉树:1、若它的左子树不为空,则左子树上所有节点的值都小于根结点的值。
- 本文的目的是用springboot整合mybatis实现一个简单的一对多查询。(查询一个用户有多少件衣服)第一步:数据库中,可以直接在nav
- 下面就来分享工具类的内容:使用范围:JavaBean类对象的属性不能是数组、List、Set、Mappublic class MapBean
- openid可以标识一个用户,session_key会变,所以来获取一下openid。openid不能在微信小程序中直接获取,需要后台发送请
- 前面做了app微信支付的回调处理,现在需要做微信公众号的支付,花了一天多时间,终于折腾出来了!鉴于坑爹的微信官方没有提供Java版的demo
- 前言C# 11 中即将到来一个可以让重视性能的开发者狂喜的重量级特性,这个特性主要是围绕着一个重要底层性能设施 ref 和 struct 的
- 第一部分 问题描述1.1 具体任务本次作业任务是轨迹压缩,给定一个GPS数据记录文件,每条记录包含经度和维度两个坐标字段,所有记录的经纬度坐
- 首先说说什么叫回调函数?在WINDOWS中,程序员想让系统DLL调用自己编写的一个方法,于是利用DLL当中回调函数(CALLBACK)的接口
- 本文实例为大家分享了java生成随机验证码图片的具体代码,供大家参考,具体内容如下1.controller /**  
- 1、SpringSecurity 本质是一个过滤器链SpringSecurity 采用的是责任链的设计模式,它有一条很长的过滤器链。现在对这
- 本文基于jdk1.8进行分析。ReentrantLock是一个可重入锁,在ConcurrentHashMap中使用了ReentrantLoc
- 背景:当我们有需求将HashMap转为Json格式的String时,切记不要使用HashMap的toString()方法,需要使用FastJ
- springboot配置文件中属性变量引用@@这种属性应用方式是field_name=@field_value@。两个@符号是springb
- 前言CompletableFuture实现了CompletionStage接口和Future接口,前者是对后者的一个扩展,增加了异步回调、流
- 在项目中用到了MapStruct,对其可以转换JavaBean特别好奇,因为之前都是使用Vo的方式手动set转换,但是接触到MapStruc
- //创建站点地图 private void Create
- 一些Java项目中在mybatis与spring整合中有MapperScannerConfigurer的使用,该类通过反向代理自动生成基于接