How can I extract a hyper开发者_JAVA技巧link from some cell in excel table using Delphi?
you can use the Hyperlinks.Address
property
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;
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:
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;
精彩评论