table-layout:fixed使单元格宽度失效解决方法

<!-- 表格处理(增强修正版) --> <xsl:template match="w:tbl"> <xsl:variable name="colCount" select="count(w:tblGrid/w:gridCol)"/> <fo:table table-layout="fixed" width="100%" border-collapse="collapse"> <!-- 生成精确列定义 --> <xsl:for-each select="w:tblGrid/w:gridCol"> <fo:table-column column-width="{@w:w div 20}pt"/> </xsl:for-each> <fo:table-body> <!-- 列溢出检测逻辑 --> <xsl:if test="count(w:tr[1]/w:tc) > $colCount"> <fo:table-row> <fo:table-cell number-columns-spanned="{$colCount}"> <fo:block color="red">表格列数溢出警告</fo:block> </fo:table-cell> </fo:table-row> </xsl:if> <xsl:apply-templates select="w:tr"/> </fo:table-body> </fo:table> </xsl:template> <!-- 表格行处理(优化版) --> <xsl:template match="w:tr"> <fo:table-row> <!-- 过滤已合并的单元格 --> <xsl:apply-templates select="w:tc[not(w:tcPr/w:vMerge/@w:val='continue')]"/> </fo:table-row> </xsl:template> <!-- 单元格处理(合并修复最终版) --> <xsl:template match="w:tc"> <fo:table-cell border="1pt solid black" padding="2pt" display-align="center" text-align="center"> <!-- 增加水平居中 --> <!-- 列合并修复 --> <xsl:variable name="totalCols" select="count(ancestor::w:tbl/w:tblGrid/w:gridCol)"/> <xsl:variable name="precedingSpanSum"> <xsl:choose> <xsl:when test="preceding-sibling::w:tc"> <xsl:value-of select="sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val) + count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </xsl:variable> <!-- 列跨度计算 --> <xsl:if test="w:tcPr/w:gridSpan"> <xsl:variable name="declaredSpan" select="w:tcPr/w:gridSpan/@w:val"/> <xsl:variable name="remainingCols" select="$totalCols - $precedingSpanSum"/> <xsl:attribute name="number-columns-spanned"> <xsl:choose> <xsl:when test="$declaredSpan > $remainingCols"> <xsl:value-of select="$remainingCols"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$declaredSpan"/> </xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:if> <!-- 行合并修复 --> <xsl:if test="w:tcPr/w:vMerge[@w:val='restart']"> <!-- 精确计算后续连续合并行数 --> <xsl:variable name="currentPos" select="count(preceding-sibling::w:tc) + 1"/> <xsl:variable name="actualRowSpan" select="count(following-sibling::w:tr[ position() <= 10 and w:tc[position()=$currentPos]/w:tcPr/w:vMerge/@w:val='continue' ]) + 1"/> <xsl:attribute name="number-rows-spanned"> <xsl:value-of select="number($actualRowSpan)"/> <!-- 移除原错误限制 --> </xsl:attribute> </xsl:if> <fo:block linefeed-treatment="ignore" white-space-collapse="true"> <xsl:apply-templates select=".//w:p"/> </fo:block> </fo:table-cell> </xsl:template>上述xslt脚本中表格处理行合并单元格没事,但是列合并单元格失效,怎么修改,请给出修改好的完成脚本,注意:上述代码为word的xml转xsl-fo,且xml和xslt的版本都为1.0
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值