2010-07-17 1 views
1

일부 태그의 배경색을 설정하고 싶습니다. CSS 배경색이나 bgcolor 속성이 작동하지 않는 것 같습니다.엑셀 용 HTML을 생성하기 위해 xsl을 사용하면 더 많은 서식이 필요합니다.

배경색을 줄 수있는 CSS가 있습니까?

Perl, XSL 전용, 아니요 Microsoft 제품. 최신 버전의 Excel에서는 OS X 및 Windows에서 작동합니다. 사람이 걱정하는 경우

xml: <d>Y</d> 
html: <td class="Status Y" bgcolor="yellow">Y</td> 
css: .Status.Y { background-color: yellow; } 

, 전체 XSL 당신은 하나의 값 클래스의 속성을 사용하고 그에 따라 CSS를 조정해야 할 수도 있습니다

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="html" 
     encoding="UTF-8" 
     indent="yes" 
     omit-xml-declaration="yes" 
    /> 
    <xsl:template match="project"> 
     <html> 
      <head> 
       <title> 
        <xsl:text>pqs - </xsl:text> 
        <xsl:value-of select="table[@id='Head']/caption/row[1]/d[1]"/> 
       </title> 
       <style type="text/css"> 
       table,th,td { 
        border-width: thin; 
        border-style: outset; 
        border-color: gray; 
        border-collapse: collapse; 
        background-color: white; 
        mso-width-source:auto; 
       } 
       th,td { 
        padding: 0 1em 0 1em; 
        border-style: inset; 
       } 
       .Status { text-align: center; } 
       .Status.G { background-color: #0F0; } 
       .Status.R { background-color: red; } 
       .Status.Y { background-color: yellow; } 
       .Status.I { background-color: #6F00FF; } 
       </style> 
      </head> 
      <body> 
       <xsl:apply-templates select="node()"/> 
      </body> 
     </html> 
    </xsl:template> 
    <xsl:template match="table|caption"> 
     <xsl:if test="@id"> 
      <h1><xsl:value-of select="@id"/></h1> 
     </xsl:if> 
     <xsl:apply-templates select="caption"/> 
     <xsl:if test="count(row)&gt;0" > 
      <table id="{@id}" class="{local-name(.)}"> 
       <xsl:apply-templates select="row"/> 
      </table> 
     </xsl:if> 
    </xsl:template> 
    <xsl:template match="row"> 
     <tr><xsl:apply-templates select="node()"/></tr> 
    </xsl:template> 
    <xsl:template match="h"> 
     <th><xsl:value-of select="@name"/></th> 
    </xsl:template> 
    <xsl:template match="d"> 
     <td> 
      <xsl:variable name="text" select="text()"/> 
      <xsl:variable name="p" select="position()"/> 
      <xsl:variable name="class" select="../../row[1]/h[$p]/@name"/> 
      <xsl:choose> 
       <xsl:when test="$class='Status'"> 
        <xsl:attribute name="class"> 
         <xsl:value-of select="concat($class,' ',$text)"/> 
        </xsl:attribute> 
        <xsl:attribute name="bgcolor"> 
         <xsl:choose> 
          <xsl:when test="$text='G'"><xsl:value-of select="'green'"/></xsl:when> 
          <xsl:when test="$text='R'"><xsl:value-of select="'red'"/></xsl:when> 
          <xsl:when test="$text='Y'"><xsl:value-of select="'yellow'"/></xsl:when> 
          <xsl:when test="$text='I'"><xsl:value-of select="'#6F00FF'"/></xsl:when> 
          <xsl:otherwise><xsl:value-of select="white"/></xsl:otherwise> 
         </xsl:choose> 
        </xsl:attribute> 
       </xsl:when> 
      </xsl:choose> 
      <xsl:value-of select="text()"/> 
     </td> 
    </xsl:template> 
</xsl:stylesheet> 
+1

포스트는 생각하지 않는다 코드가 작동하는 것. 이 XML은 어디에 표시됩니까? 브라우저? 변형은 어떻게 생겼습니까? – Pointy

+0

xml을 볼 수 없습니다. 그것은 엑셀에서 사용하기 위해 html로 변환됩니다. –

답변

2

입니다. 이 같은

뭔가 :

html: <td class="StatusY" bgcolor="yellow">Y</td> 
css: .StatusY { background-color: yellow; } 

엑셀가하는 여러 class 속성 값을 처리 할 수 ​​ 표시되지 및 복합 클래스 값에 대한 CSS 선택기를 적용 할 수 보이지 않습니다.

background-color은 CSS 선택기가 하나의 클래스 속성 값을 갖는 요소에 대해 단일 클래스 속성에 적용되는 경우 Excel에서 작동합니다.

내가 무엇을 의미하는지에 관해 알기 위해 Excel에서이 예제 HTML 문서를 살펴 보자 :

<html xmlns:o="urn:schemas-microsoft-com:office:office" 
xmlns:x="urn:schemas-microsoft-com:office:excel" 
xmlns="http://www.w3.org/TR/REC-html40"> 
    <head> 
     <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> 
     <meta name="ProgId content=Excel.Sheet"> 
     <meta name="Generator" content="Microsoft Excel 10"> 
     <style> 
      <!-- 
table{ border:1px solid black;} 
td{ border:1px solid black;} 
.Y {background-color:#0000FF;} 
.Status{background-color:#00FF00;} 
.Status.Y {background-color:#FF0000;} 
.StatusY {background-color:#CCCCCC;} 
--> 
     </style> 
    </head> 
    <body> 
     <table> 
      <tr> 
       <td class="Y">class="Y"</td> 
      </tr> 
      <tr> 
       <td class="Status">class="Status"</td> 
      </tr> 
      <tr> 
       <td class="Status Y" >class="Status Y"</td> 
      </tr> 
      <tr> 
       <td class="StatusY" >class="StatusY"</td> 
      </tr> 
      <tr> 
       <td>no class</td> 
      </tr> 
     </table> 
    </body> 
</html> 
+0

머리에 손톱이 부딪쳤다! 감사합니다. Microsoft가 처음으로 CSS를 단일 클래스로 구현했음을 잊기 쉽습니다. 그것은 불행한 의미가 있습니다. –

관련 문제