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 hereExcel.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#连接excel示例分享
- C#连接Excel驱动与示例代码分享
- C#在excel中添加超链接
- c# .Net :Excel NPOI导入导出操作教程之数据库表信息数据导出到一个Excel文件并写到磁盘示例分享
- C#/VB.NET对EXCEL图片添加超链接
- c# 在 excel中添加超链接
- C#/VB.NET对EXCEL图片添加超链接
- C# .Net :Excel NPOI导入导出操作教程之将Excel文件读取并写到数据库表,示例分享
- c#操作json示例分享
- c#生成随机数示例分享
- C#中添加excel引用
- java向文件末尾添加内容示例分享
- c#中高效的excel导入sqlserver的示例
- ASP.NET(C#) 读取EXCEL另加解决日期问题的方法分享
- C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化
- C# 如何向Excel添加、删除表单控件
- C#向Word文档中添加内容控件的方法示例
- C#操作Excel数据增删改查示例
- ASP.NET(C#) 读取EXCEL另加解决日期问题的方法分享