delphi excel超链接在一个单元格中

如何使用Delphi从excel表格中的某个单元格中提取超链接?

您可以使用Hyperlinks.Address属性

检查这个代码

 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; 

如果您的预算中有50美元用于精简的Delphi代码库,可以在不使用OLE的情况下读取和写入Excel文件,或者需要使用Excel,那么您可以尝试NativeExcel 。 它快速,易于使用,附带一个点对点的帮助文件,并且可以很好地控制您创build的工作簿。 以下是从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;