How can I extract a hyperlink from some cell in excel table using Delphi?
如何使用Delphi从excel表中的某些单元格中提取超链接?
2 个解决方案
#1
6
you can use the Hyperlinks.Address
property
您可以使用Hyperlinks.Address属性
check this code
检查此代码
var
excel : Variant;
begin
Excel := CreateOleObject('Excel.Application');//Create an excel instance
try
Excel.Workbooks.Open('yourexcelfile.xls'); //open the excel workbook
if Excel.Range['B4', 'B4'].Hyperlinks.Count > 0 then //check if exist hyperlinks in the range
ShowMessage(Excel.Range['B4', 'B4'].Hyperlinks[1].Address); //show the hyperlink
finally
if not VarIsEmpty(Excel) then
Excel.Quit; //Close the excel instance
end;
end;
#2
1
If you have 50 bucks in your budget for a slick library of Delphi code to read and write Excel files without using OLE or requiring Excel to be present, you could try NativeExcel. It's fast, easy to use, comes with a to-the-point help file, and gives you great control over the workbooks you create. Here's the code to read the value from A1:
如果你的预算有50美元用于一个光滑的Delphi代码库来读取和写入Excel文件而不使用OLE或要求Excel存在,你可以尝试使用NativeExcel。它快速,易于使用,附带一个即点帮助文件,让您可以很好地控制您创建的工作簿。这是从A1读取值的代码:
procedure TForm1.Button1Click(Sender: TObject);
Var Book: IXLSWorkbook;
ws: IXLSWorksheet;
sHyperlink: String;
begin
Book := TXLSWorkbook.Create;
Book.Open('C:\Data\Book1.xls');
ws := Book.Sheets[1];
ShowMessage(ws.Range['A1','A1'].HyperLinks[1].Address);
end;
#1
6
you can use the Hyperlinks.Address
property
您可以使用Hyperlinks.Address属性
check this code
检查此代码
var
excel : Variant;
begin
Excel := CreateOleObject('Excel.Application');//Create an excel instance
try
Excel.Workbooks.Open('yourexcelfile.xls'); //open the excel workbook
if Excel.Range['B4', 'B4'].Hyperlinks.Count > 0 then //check if exist hyperlinks in the range
ShowMessage(Excel.Range['B4', 'B4'].Hyperlinks[1].Address); //show the hyperlink
finally
if not VarIsEmpty(Excel) then
Excel.Quit; //Close the excel instance
end;
end;
#2
1
If you have 50 bucks in your budget for a slick library of Delphi code to read and write Excel files without using OLE or requiring Excel to be present, you could try NativeExcel. It's fast, easy to use, comes with a to-the-point help file, and gives you great control over the workbooks you create. Here's the code to read the value from A1:
如果你的预算有50美元用于一个光滑的Delphi代码库来读取和写入Excel文件而不使用OLE或要求Excel存在,你可以尝试使用NativeExcel。它快速,易于使用,附带一个即点帮助文件,让您可以很好地控制您创建的工作簿。这是从A1读取值的代码:
procedure TForm1.Button1Click(Sender: TObject);
Var Book: IXLSWorkbook;
ws: IXLSWorksheet;
sHyperlink: String;
begin
Book := TXLSWorkbook.Create;
Book.Open('C:\Data\Book1.xls');
ws := Book.Sheets[1];
ShowMessage(ws.Range['A1','A1'].HyperLinks[1].Address);
end;