PHPExcel str_replace
PHPExcel str_replace
我想转换我的 excel 超链接路径以使用 PHPExcel 打开链接。
$links = $objPHPExcel->getActiveSheet()->getHyperlinkCollection();
此方法将return超链接对象数组,按单元格地址索引;然后您可以将 array_filter() 与适当的回调一起使用,并设置 ARRAY_FILTER_USE_KEY 标志以提取特定范围内的那些。
我的var_dump($links);输出:
但我不知道如何使用 array_filter() 函数循环对象数组..
我试试 :
$test = str_replace($links, "file", "mnt");
var_dump($test);
我得到了上面的错误..有什么想法吗?
该集合是一个对象数组,由单元格地址索引; PHPExcel_Cell_Hyperlink
对象有一组记录的方法来访问和设置它的数据:
foreach($links as $cellAddress => $link) {
// get the URL from the PHPExcel_Cell_Hyperlink object
$url = $link->getUrl();
// change the URL however you want here
$url = str_replace($url, "file", "mnt");
// Set the new value for the link
$link->setUrl($url);
}
如果您只想修改 N
列中单元格的 URL,则可以将它们包装在 if
测试中:
foreach($links as $cellAddress => $link) {
// Test for column N
sscanf($cellAddress, '%[A-Z]%d', $column, $row);
if ($column == 'N') {
// get the URL from the PHPExcel_Cell_Hyperlink object
$url = $link->getUrl();
// change the URL however you want here
$url = str_replace($url, "file", "mnt");
// Set the new value for the link
$link->setUrl($url);
}
}
我想转换我的 excel 超链接路径以使用 PHPExcel 打开链接。
$links = $objPHPExcel->getActiveSheet()->getHyperlinkCollection();
此方法将return超链接对象数组,按单元格地址索引;然后您可以将 array_filter() 与适当的回调一起使用,并设置 ARRAY_FILTER_USE_KEY 标志以提取特定范围内的那些。
我的var_dump($links);输出:
但我不知道如何使用 array_filter() 函数循环对象数组..
我试试 :
$test = str_replace($links, "file", "mnt");
var_dump($test);
我得到了上面的错误..有什么想法吗?
该集合是一个对象数组,由单元格地址索引; PHPExcel_Cell_Hyperlink
对象有一组记录的方法来访问和设置它的数据:
foreach($links as $cellAddress => $link) {
// get the URL from the PHPExcel_Cell_Hyperlink object
$url = $link->getUrl();
// change the URL however you want here
$url = str_replace($url, "file", "mnt");
// Set the new value for the link
$link->setUrl($url);
}
如果您只想修改 N
列中单元格的 URL,则可以将它们包装在 if
测试中:
foreach($links as $cellAddress => $link) {
// Test for column N
sscanf($cellAddress, '%[A-Z]%d', $column, $row);
if ($column == 'N') {
// get the URL from the PHPExcel_Cell_Hyperlink object
$url = $link->getUrl();
// change the URL however you want here
$url = str_replace($url, "file", "mnt");
// Set the new value for the link
$link->setUrl($url);
}
}