2010-09-08 133 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; 
相關問題