解析Excel2007之不得不说的rels文件

来源于:http://gaby.cnblogs.com/

作者:Gaby,昵称:木头

说明:本人能力有限,所有文章均作为自己的学习笔记,如果不对或者不合理的地方, 欢迎留言提出,谢谢支持!

注:所有解析都是根据这个我自定义的Excel文件进行的【单击下载

 

上一篇《解析Excel2007之文档结构》我们看了Excel2007的文档结构,我们看到里面到处都是rels文件,具体它是干什么的呢?

其实它就是文档结构中的文件相关关联的关系存储文件,我们应该很容易理解,在一个Excel2007的xlsx文件居然是一个文件压缩包,那文件之间的关联是如何管理的?就是靠它,rels文件。

我们先看最顶级的rels文件,也就是根目录下的.rels文件夹中的文件内容,如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
  <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
</Relationships>

很容易看明白哦

Id:就是Id啦,标识;

Type:文件类型定义

Target:目标文件,存储的是相对路径

文件加载的时候最先找到并用上的就是这个三个关联文件了。

 

前面说过,docProps/app.xml和docProps/core.xml我们应该是用不上的,我们就不管

我们来看xl/workbook.xml,这个文件就是这个Excel文件的主文件,由于这个文件比较简单,我就不做单独的分析了,在这里带过了。先看里面的内容

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
  <fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4506"/>
  <workbookPr filterPrivacy="1" defaultThemeVersion="124226"/>
  <bookViews>
    <workbookView xWindow="0" yWindow="90" windowWidth="19200" windowHeight="11640"/>
  </bookViews>
  <sheets>
    <sheet name="Sheet1" sheetId="1" r:id="rId1"/>
    <sheet name="Sheet2" sheetId="2" r:id="rId2"/>
    <sheet name="Sheet3" sheetId="3" r:id="rId3"/>
  </sheets>
  <calcPr calcId="125725"/>
</workbook>

还是一个一个来看

fileVersion:文件版本号,里面的内容我也不清楚,appName应该是应用名,lastEdited应该是最后编辑,但是我不知道4是什么意思?修改的版本号?像svn一样的?

workbookPr:性能参数

bookViews:这个不好说了,我原以为是控制文档打开时显示到屏幕上的位置和大小,可是我修改过后没有效果。谁知道给我留言吧。

sheets:这个知道了吧,就是Excel表格里面的sheet。name:就是sheet的名字,用来显示的;sheetId:Id标识咯;r:id:这个第一次看到了吧,呵呵,这个就是该sheet关联的文件在rels中定义的Id咯,看这里sheet1的r:id是rId1,对应的上面的rels文件里面Id=”rId1”,对应的目标文件就是sheet1.xml文件了。

calcPr:这个又不知道了,好像跟计算公式有关,但是我删除过后,Excel文件也正常。

xl文件夹下的rels文件内容是workbook.xml.rels文件,文件内容如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet3.xml"/>
  <Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain" Target="calcChain.xml"/>
  <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet2.xml"/>
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>
  <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>
  <Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
  <Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>
</Relationships>

看到上面说的rId1了吧,后面就是worksheets/sheet1.xml。

 

好了,通过上面说明应该对rels文件有一定了解了,那就到这吧。

转载于:https://www.cnblogs.com/Gaby/archive/2009/04/30/1447068.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值