如何从word和excel中批量提取超链接

如何从word和excel中批量提取超链接,第1张

word和excel批量提取超链接的具体步骤是:工具>宏>宏>创建(excel为Visual Basic编辑器),打开编辑器,将如下代码插入模块:

word文档插入代码:

Sub 超级链接()

For Each aHyperlink In ActiveDocumentHyperlinks

With Selection

InsertAfter aHyperlinkName

Collapse Direction:=wdCollapseEnd

InsertParagraphAfter

End With

Next aHyperlink

End Sub

excel文档插入代码:

Sub ExtractHL()

Dim HL As Hyperlink

For Each HL In ActiveSheetHyperlinks

HLRangeOffset(0‚ 1)Value = HLAddress

Next

End Sub

将代码插入后,点运行即可。word文档会将超链接的URL显示在光标所在处,excel会将URL显示在含超链接的单元格的右侧单元格内。

PHP从URL中提取网址,这里使用正则匹配preg_match()函数来实现,分两步来 *** 作,第1步是从URL中提取主机名,第2步从主机名中提取得到后两段,通过这个具体示例你会对preg_match的用法有一个更深的了解。

1 <php

2 // 从 URL 中取得主机名

3 preg_match("/^(>

可以用getAttribute()方法获取。

注:总结了一些getAttribute(),setAttribute()在不同浏览器下兼容性以及如何解决这些问题

body里面有这些内容:

<div id="idHeader" class="class-header" title="kingwell" status="1"></div>

<label id="forUserName" for="userName" title="kingwell" status="1"></label>

下面是script的测试:

var el = documentgetElementById("idHeader");

alert(elgetAttribute("id"));

alert(elid);

IE Firfox->idHeader

alert(elgetAttribute("class"));

//IE6,IE7 -> null IE8,IE9,Firefox ->class-header

alert(elclass);

//IE6,IE7,IE8->报错 IE9,Firefox->undefined

alert(elgetAttribute("className"));

//IE6,IE7->class-header ; IE8,IE9,Firefox -> undefined

alert(elclassName);

//All -> class-header

var elfor = documentgetElementById("forUserName");

alert(elforgetAttribute("for"));

//IE6,IE7->undefined IE8,9,Firefox->forUseName

alert(elforfor )

//IE6,IE7报错,其它为undefined

alert(elfortitle)

//全部输出kingwell

alert(elforstatus);

//IE6-8 -> 1 IE9,Firefox->undefined

alert(elforgetAttribute("status"))

//全部输出 1

总结:

1:常规属性建议使用 nodeXXXX。

2:自定义属性建议使用nodegetAttribute("XXXX")。

3:当获取的目标是JS里的关键字时建议使用nodegetAttribute("XXX"),如label中的for。

4:当获取的目标是保留字,如:class,请使用className代替。

import javaawtBorderLayout;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaioBufferedReader;

import javaioIOException;

import javaioInputStream;

import javaioInputStreamReader;

import javanet>

用js 的方法获取:代码如下

设置或获取对象指定的文件名或路径。

alert(windowlocationpathname)

设置或获取整个 URL 为字符串。

alert(windowlocationhref);

设置或获取与 URL 关联的端口号码。

alert(windowlocationport)

设置或获取 URL 的协议部分。

alert(windowlocationprotocol)

设置或获取 href 属性中在井号“#”后面的分段。

alert(windowlocationhash)

设置或获取 location 或 URL 的 hostname 和 port 号码。

alert(windowlocationhost)

设置或获取 href 属性中跟在问号后面的部分。

alert(windowlocationsearch)

获取变量的值(截取等号后面的部分)

var url = windowlocationsearch;

// alert(urllength);

// alert(urllastIndexOf('='));

var loc = urlsubstring(urllastIndexOf('=')+1, urllength);

这个js都有这功能:

windowlocationhref:设置或获取整个 URL 为字符串

windowlocationpathname:设置或获取对象指定的文件名或路径

windowlocationsearch:设置或获取 href 属性中跟在问号后面的部分

要获取变量的值可以试试:

var urlParam= windowlocationsearch;

var loc = urlParamsubstring(urlParamlastIndexOf('=')+1, urlParamlength);

如果是多个参数可以分布切割,得到多个键值对。

希望可以帮到你。

用select 语句提取,然后在输出的时候,直接硬编码html元素,例如:

echo '<a href="'$row["add"]' target="_blank">',

其中$row["add"]是要根据你的实际代码来改一下的

以上就是关于如何从word和excel中批量提取超链接全部的内容,包括:如何从word和excel中批量提取超链接、如何获取网页的url、如何用Javascript获取超链接的链接地址等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9500827.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存