以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何设置超链接(链接到同一个excel工作簿的其他工作表)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=145281)

--  作者:季朝龙
--  发布时间:2020/1/14 17:32:00
--  如何设置超链接(链接到同一个excel工作簿的其他工作表)
如何设置超链接(链接到同一个excel工作簿的其他工作表),希望单机“项目总表”的每个项目,可以打开对应的项目明细,工作簿定义代码如下:


Dim dt As Table = Tables("项目总表")
Dim dt1 As Table = Tables("项目总表.AA")
Dim Book As New XLS.Book \'定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
Dim Style As Xls.Style = Book.NewStyle \'新建一个样式
Style.BackColor = Color.Red \'样式的背景颜色设为红色
For c As Integer = 0 To dt.Cols.Count -1 \'添加列标题
    Sheet(0, c).Value = dt.Cols(c).Name
Next
For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
CurrentTable.Position = r
    book.Sheets.Add(dt.rows(r)(0))
    Dim Sheet1 As XLS.Sheet = Book.Sheets(r+1) \'循环引用工作簿的工作表
    For c1 As Integer = 0 To dt1.Cols.Count -1
        Sheet1(0, c1).Value = dt1.Cols(c1).Name
    Next
    For r1 As Integer = 0 To dt1.Rows.Count - 1
        For c0 As Integer = 0 To dt1.Cols.Count -1
            Sheet1(r1 +1, c0).Value = dt1.rows(r1)(c0)
        Next
        
    Next
    For c As Integer = 0 To dt.Cols.Count -1
        Sheet(r +1, c).Value = dt.rows(r)(c)
    Next
Sheet(r+1,0).Hyperlink = Book.Sheets(r+1)(狐狸爸爸帮我看看这句代码该怎么改)
Next
\'打开工作簿
Book.Save("c:\\reports\\test.xls")
Dim Proc As New Process
Proc.File = "c:\\reports\\test.xls"
Proc.Start()



--  作者:有点蓝
--  发布时间:2020/1/14 20:23:00
--  
上面这种用不了,需要使用vba:http://www.foxtable.com/webhelp/topics/2121.htm

Dim App As New MSExcel.Application

Dim Wb As MSExcel.Workbook = App.WorkBooks.Open("D:\\123.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim range  = Ws.Range("A1")
Ws.HyperLinks .Add (range,"#Sheet2!B3" ,"","提示文字","链接文字")
Wb.Save
App.Visible = True