[英]Get Excel HyperLink Cell String
I'm trying to get the hyperlink string from an Excel cell using the excel data reader library in C#, but retrieving the cell and calling the ToString method didn't work.我正在尝试使用 C# 中的 excel 数据读取器库从 Excel 单元格获取超链接字符串,但检索单元格并调用 ToString 方法无效。
This is my code so far:到目前为止,这是我的代码:
using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read)){
using var reader = ExcelReaderFactory.CreateReader(stream);
var result = reader.AsDataSet();
DataTable table = result.Tables[0];
bool jumpCol = true; // Avoid first lane
foreach (DataRow row in table.Rows)
{
if (jumpCol)
{
jumpCol = false;
continue;
}
}
PlateImage = row[6].ToString(); //This returns 0
I just need the hyperlink string:我只需要超链接字符串:
=HYPERLINK("thisString.jpg")
Any ideas?有任何想法吗? Any library that allows me to do this?
任何允许我这样做的图书馆吗?
Install Free Spire.XLS from NuGet: Install-Package FreeSpire.XLS从 NuGet 安装免费的 Spire.XLS: Install-Package FreeSpire.XLS
Next, you can read the hyperlinks from Excel with the following code:接下来,您可以使用以下代码读取来自 Excel 的超链接:
using Spire.Xls;
using System;
namespace RetrieveHyperlink
{
class Program
{
static void Main(string[] args)
{
Workbook wb = new Workbook();
wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Hyperlinks.xlsx");
Worksheet sheet = wb.Worksheets[0];
foreach (var item in sheet.HyperLinks)
{
string address = item.Address;
CellRange range = item.Range;
Console.WriteLine(string.Format("Cell[{0},{1}] contains URL: {2}", range.Row, range.Column, address));
}
}
}
}
Keep in mind that the free version has a limitation of 5 sheets and 200 rows per sheet for .xls file format.请记住,对于.xls文件格式,免费版本有 5 张和每张 200 行的限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.