我一直试图在openTBS生成的文档中使链接工作。到目前为止没有运气:
我完全迷路了,花了几天时间想办法解决这个问题。这让我烦恼不已,因为这似乎是openTBS自己可以自己处理的事情,没有问题。
I这是我的php代码:
<?
include_once('tbs/tbs_class.php');
include_once('tbs/plugins/tbs_plugin_opentbs_1.8.1/tbs_plugin_opentbs.php');
$TBS = new clsTinyButStrong('!-,-!');
//the special pattern is needed because
//word replaces [] brackets when put in link's href.
$TBS -> Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
//some variables for mergeing with the template
$tmpl_headname='Sarah';
$tmpl_headlink='http://example.com/?user=sarah';
$tmpl_items = array(
array('title'=>'My title', 'url'=>'http://myurl.com/firstarticle'),
array('title'=>'My second title', 'url'=>'http://myurl.com/secondarticle'),
array('title'=>'My third title', 'url'=>'http://myurl.com/thirdarticle')
);
$TBS->LoadTemplate('sampledoc.docx');
$TBS->MergeBlock('item',$tmpl_items);
$TBS->Show(OPENTBS_DOWNLOAD, 'sample_filename_doc');
?>我的文字模板:
This is your unique link, !-onload.tmpl_headname-! (points to: !- onload.tmpl_headlink-!)
!-item;block=begin;tbs:page-!
!-item.title-!
Link to the website (points to: !-item.url-!)
***
!-item;block=end;tbs:page-!在我的Word模板中,链接指向!-item.url-!,在它上运行openTBS之后,链接保持不变。问题是,在Docx存档中,在word/_rels/document.xml.rels˙中,它们看起来没有变化:
<Relationship TargetMode="External" Target="!-item.url-!" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Id="rId8"/>任何帮助都是非常感谢的!:)
另外,对于那些想用openTBS更改链接urls的人(但不是在mergeblock模式下!),我找到了一个解决办法:打开document.xml.rels作为模板,然后在它上运行一个openTBS:
$TBS->LoadTemplate('tbs/sampledoc.docx#word/_rels/document.xml.rels');这个黑客不适用于mergeblock,因为!-item.url-!获取为每个资源的目标,并且您无法判断哪个块迭代用于哪个块迭代:(
编辑:
OpenTBS生成带有rId前缀的in:rId1、rId2等。资源文件中的每个其他项都以rId[x]模式链接。运行openTBS后,我将在document.xml中获得以下xml代码,表示以下Word部分:
***
My second title
Link to the website 与一个链接上的“链接到网站”位。..。
<w:p w:rsidRDefault="00886D12" w:rsidP="00886D12">
<w:r>
<w:t xml:space="preserve">
***
</w:t>
</w:r>
<w:r>
<w:br/>
</w:r>
<w:r>
<w:t>
My second title
</w:t>
</w:r>
<w:r>
<w:br/>
</w:r>
<w:hyperlink r:id="rId7" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t xml:space="preserve">
Link to the website
</w:t>
</w:r>
</w:hyperlink>
</w:p>
...document.xml.rels文件如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/>
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>
<Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="!-item.url-!" TargetMode="External"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml" Target="../customXml/item1.xml"/>
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/>
<Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/>
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml"/>
<Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>
</Relationships>我可能能够使用放置在目标属性中的特殊openTBS代码复制超链接资源项,但是接下来我也必须在document.xml上使用新的rIDs。
谢谢你的帮忙!
发布于 2013-11-04 12:50:58
是的,弄好了!因此,根据Sarah的建议,我能够伪造Word文档的rels文件和document.xml中的rId链接。
我就是这样做的:
http://mypage.com,您选择哪个url并不重要,原因如下:在块被乘以几次之后,这些块中的所有链接都将保持链接到rels文件中的同一个<Realtionship>标记,而且我们将修改这个连接,因此没有链接将指向原始的mypage.com <Relationship>项。!-item.rId;att=w:hyperlink#r:id;-!,所以我的链接现在看起来是:My website!-item.rId;att=w:hyperlink#r:id;-!。此标记所做的是更改链接的默认r:id属性(即document.xml和_rels/document.xml.rels文件之间的属性Word链接项)。 r:id将更改为自定义id名称,您必须在合并的php数组中提供它!这里是rId的php代码:
$tmpl_items =数组(数组(‘title’=‘My’>,‘url’=‘http://myurl.com/firstarticle’>,'rId‘=> 'linkRid1'),
数组(‘array=’>‘我的第二个标题’,‘url’=‘http://myurl.com/secondarticle’>,'rId‘=> 'linkRid2'),数组(’title‘=’‘>’我的第三个标题‘,’url‘=’http://myurl.com/thirdarticle‘,'rId’=>‘linkRid3’‘);
注意,rId是我们将用默认的r:ids替换的值。当然,openTBS标记将从链接文本中删除。!-item.block;block=begin;-! <Relationship Id="!-item.rId-!" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="!-item.url-!" TargetMode="External"/> !-item.block;block=end;-!<Relationship>项也将由openTBS生成。另外,这意味着,到现在为止,Word文件已经损坏,因为您破坏了rels文件中的有效XML语法,并且无法在Word中进行编辑。
$TBS->LoadTemplate('tbs/sampledoc_stackof2.docx');$TBS->MergeBlock('item',$tmpl_items);$TBS->LoadTemplate('#word/_rels/document.xml.rels');$TBS->MergeBlock('item',$tmpl_items);经过这么多麻烦,一切看起来都是-好的。我在rels档案里有这些:
<Relationship Id="linkRid1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://myurl.com/firstarticle" TargetMode="External"/>
<Relationship Id="linkRid2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://myurl.com/secondarticle" TargetMode="External"/>
<Relationship Id="linkRid3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://myurl.com/thirdarticle" TargetMode="External"/>我在document.xml里也买到了果岭:
<w:p w:rsidRDefault="004842D8" w:rsidP="008A11F0">
<w:hyperlink r:id="linkRid1" w:history="1">
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>
My website
</w:t>
</w:r>
</w:hyperlink>
</w:p>现在在文档上运行openTBS将使用合并的链接对docx文件进行更新。唯一的缺点是,由于rels文件遭到黑客攻击,我失去了xml有效性,也失去了在Word中编辑文档的机会。任何建议,如何避免这将是徒劳无益的,虽然我们需要一个解决方案,在保存模板文档后,Word将保持文件中被黑客入侵的部分完整。
谢谢莎拉的大力帮助!
我现在要开一瓶酒。
发布于 2013-10-28 15:57:29
这一点很难在评论中显示出来。
您可能需要使用att参数:prm
类似于(未经测试的):
<Relationship TargetMode="External" Target="" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Id="rId8">
!-block=item;att=Target;item.url-!
</Relationship>你可以玩att=Relationship#Target,而不是像我一样打开关系标签。像这样的东西(真正未经测试):
<Relationship TargetMode="External" Target="" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Id="rId8"/>
!-block=item;att=Relationship#Target;item.url-!这是否允许块正确地重复,这样就不会将块全部分组到一个Target属性中?
显然,您还需要为每个rId属性提供一个唯一的id。您可能希望在这里学习OpenTBS的示例,并使用与Word不同的结构来避免冲突。类似于rId=mytbs1的东西,而不仅仅是rId=1 (OpenTBS使用opentbs1来获取图片,但您也不想在那里发生冲突)。
我相信Skrol29会阅读这篇文章,并将考虑是否有可能/合理地更新OpenTBS来处理这个问题。
编辑:
在看到XML之后,我最好的猜测是向填充块的数组中添加一个唯一的rId。类似于:
$items = array(
array('title' => 'My Title1', 'url' => 'http://my.url', 'rId' => 'myTBS1'),
array('title' => 'My Title2', 'url' => 'http://my.url', 'rId' => 'myTBS2'),
);然后,在模板中:
!-item;block=begin;tbs:page-!
!-item.title-!
Link to the website
***
!-item;block=end;tbs:page-!其中“链接到网站”有一个超链接,其内容是(类似):
!-block=item;item.url-!!-item.rId;att=rId-!然后在您的rels模板中:
<Relationship TargetMode="External" Target="" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Id="rId8">
!-block=item;att=Target;item.url-!
!-item.rId;att=rId-!
</Relationship>这只是一个保持rIds链接的想法。我不确定我的语法是否正确,多属性的规则在一个标签上发生了变化.希望Skrol29会有一个更好的解决方案,如果我们在这里乱七八糟的树。
https://stackoverflow.com/questions/19637390
复制相似问题