2010-09-08 220 views
2

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

+0

当您尝试提取单元格的内容时,会得到什么结果? – 2010-09-08 22:00:34

+0

我得到超链接的文本,但不是地址。 – user285070 2010-09-08 22:10:01

回答

6

如果你有50块钱,你可以使用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; 
1

在你的预算的Delphi代码光滑的库,而无需使用OLE或需要读写Excel文件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; 
相关问题