c#生成Excel时,如果给内容加超链接?
RT
顺祝大家中秋节快乐!
--------------------编程问答-------------------- 帮助文档里面有啊 --------------------编程问答--------------------
什么帮忙文档? --------------------编程问答--------------------
CSDN没人了? --------------------编程问答--------------------
--------------------编程问答-------------------- 补充一下,以上代码是C#4.0,Excel 2010,如果你的环境不一样可能需要少量修改代码。 --------------------编程问答-------------------- 帮忙顶下,LS貌似可以 --------------------编程问答-------------------- Worksheet ThisSheet = new Worksheet();
// Import C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll
// Import C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Drawing.dll
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading;
namespace InteropExcelChart
{
class Program
{
static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application excel =
new Microsoft.Office.Interop.Excel.ApplicationClass();
var book = excel.Workbooks.Add();
excel.Visible = true;
var sheet = book.Sheets.Add() as Microsoft.Office.Interop.Excel.Worksheet;
// add link
var range = sheet.Range["A1"];
range.Value2 = "Google";
sheet.Hyperlinks.Add(range, "http://g.cn");
//
Thread.Sleep(5000);
book.Close(false);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
}
}
}
ThisSheet = (Worksheet)ThisWorkBook.ActiveSheet;
Range rn = (Range)ThisSheet.Cells[1, 1];
rn.Hyperlinks.Add(rn, "", "", missing, "");
--------------------编程问答-------------------- public void AddHyperLink(Microsoft.Office.Interop.Excel._Worksheet CurSheet, object objCell, string strAddress, string strTip, string strText)
{
CurSheet.Hyperlinks.Add(CurSheet.get_Range(objCell, objCell), strAddress, mValue, strTip, strText);
}
补充:.NET技术 , C#