如何使用C#在excel文档中创建指向文件的链接? [英] How to create a link to an file in excel document using C#?
本文介绍了如何使用C#在excel文档中创建指向文件的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过单击保存按钮来管理创建文档,但是......
Excel中的一个字段包含文件的路径。它作为字符串是正确的,但是如果是文件的链接并且点击时实际打开文件会更好。
是否可以从C#开始?
这里看起来如何(例如解释我现在做什么,我明白我的英语接近垃圾级别):
Managed to create a document by clicking on save button but...
One of the fields in Excel contains path to a file. It is correct as string, but Ito me it will be better if is was a link to file and actually opened file on click.
Is it possible to do from C#?
Here how it look (as example to explain what do Ihave right now, i understand that my english is near to trash level):
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Workbooks.Add();
Microsoft.Office.Interop.Excel._Worksheet workSheet = excel.ActiveSheet;
...
workSheet.Cells[row, "A"] = item.ActionType;
workSheet.Cells[row, "B"] = "sek: " + item.AfterClick.Seconds.ToString() + " msek: " + item.AfterClick.Milliseconds.ToString();
workSheet.Cells[row, "C"] = item.Time.ToLongTimeString();
workSheet.Cells[row, "D"] = "pic" + item.id.ToString();
workSheet.Cells[row, "E"] = string.Format(@"{0}\{1}\Pictures\pic{2}.jpeg", path, folder, item.id);
如您所见,E上的数据应该链接到文件而不是简单文本。
As you can see, the data on "E" should bve link to file instead of simple text.
推荐答案
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.hyperlinks(v = vs.90).aspx
使用
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.hyperlinks(v=vs.90).aspx
use
worksheet.HyperLink.Add(.....)
workSheet.Cells [row,E ] = string.Format(@=超链接({0} \ {1} \ Picts; \\ pic {2} .jpeg),path,folder,item.id);
workSheet.Cells[row, "E"] = string.Format(@"=Hyperlink({0}\{1}\Pictures\pic{2}.jpeg)", path, folder, item.id);
这篇关于如何使用C#在excel文档中创建指向文件的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文