c#在excel中添加超鏈接示例分享
1.新建一個(gè)項(xiàng)目
2.給項(xiàng)目添加引用:Microsoft Excel 12.0 Object Library (2007版本)
using Excel = Microsoft.Office.Interop.Excel;
3.對(duì)excel的簡(jiǎn)單操作:如下代碼“添加超鏈接”等。
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();
}
}
}
相關(guān)文章
C#訪問(wèn)SQL Server數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方法
這篇文章主要介紹了C#訪問(wèn)SQL Server數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方法,以實(shí)例形式簡(jiǎn)單分析了C#連接、查詢SQL Server數(shù)據(jù)庫(kù)的具體技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10C# Winform 實(shí)現(xiàn)控件自適應(yīng)父容器大小的示例代碼
這篇文章主要介紹了C# Winform 實(shí)現(xiàn)控件自適應(yīng)父容器大小的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03解決C#運(yùn)行程序修改數(shù)據(jù)后數(shù)據(jù)表不做更新的問(wèn)題
近日,在使用C#連接數(shù)據(jù)庫(kù)的時(shí)候,對(duì)數(shù)據(jù)庫(kù)中的表做更新后,在當(dāng)前啟動(dòng)項(xiàng)目中去顯示表數(shù)據(jù)時(shí)雖然會(huì)發(fā)生一個(gè)更新,但是在結(jié)束程序運(yùn)行后再去觀察數(shù)據(jù)表中的記錄時(shí)發(fā)現(xiàn)并沒(méi)有發(fā)生一個(gè)變化,所以本文給大家解決一下這個(gè)問(wèn)題,需要的朋友可以參考下2023-08-08C#內(nèi)置隊(duì)列類Queue用法實(shí)例
這篇文章主要介紹了C#內(nèi)置隊(duì)列類Queue用法,實(shí)例分析了C#內(nèi)置隊(duì)列的添加、移除等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04基于WPF實(shí)現(xiàn)3D畫廊動(dòng)畫效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何基于WPF實(shí)現(xiàn)簡(jiǎn)單的3D畫廊動(dòng)畫效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-02-02C# winform程序?qū)崿F(xiàn)開(kāi)機(jī)自啟動(dòng)并且識(shí)別是開(kāi)機(jī)啟動(dòng)還是雙擊啟動(dòng)
這篇文章主要介紹了C# winform程序?qū)崿F(xiàn)開(kāi)機(jī)自啟動(dòng)并且識(shí)別是開(kāi)機(jī)啟動(dòng)還是雙擊啟動(dòng)的實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10基于C#實(shí)現(xiàn)的多生產(chǎn)者多消費(fèi)者同步問(wèn)題實(shí)例
這篇文章主要介紹了基于C#實(shí)現(xiàn)的多生產(chǎn)者多消費(fèi)者同步問(wèn)題,包括了加鎖與釋放鎖,以及對(duì)應(yīng)臨界資源的訪問(wèn)。是比較實(shí)用的技巧,需要的朋友可以參考下2014-09-09原生實(shí)現(xiàn)C#與Lua相互調(diào)用方法(Unity3D可用)
Lua是一種很好的擴(kuò)展性語(yǔ)言,Lua解釋器被設(shè)計(jì)成一個(gè)很容易嵌入到宿主程序的庫(kù),下面這篇文章主要給大家介紹了關(guān)于原生實(shí)現(xiàn)C#與Lua相互調(diào)用方法,Unity3D可用的相關(guān)資料,需要的朋友可以參考下2022-04-04C#使用開(kāi)源驅(qū)動(dòng)連接操作MySQL數(shù)據(jù)庫(kù)
這篇文章主要介紹了C#使用開(kāi)源驅(qū)動(dòng)連接操作MySQL數(shù)據(jù)庫(kù),本文講解使用SourceForge上的mysqldrivercs驅(qū)動(dòng)連接操作MySQL數(shù)據(jù)庫(kù),需要的朋友可以參考下2015-02-02