【问题标题】:Excel XML: Formatting inline textExcel XML:格式化内联文本
【发布时间】:2014-03-06 01:00:59
【问题描述】:

我正在尝试将内联样式应用于 Excel 电子表格中的单元格,目的是在单个单元格中包含粗体、非粗体和不同颜色的文本。

我正在使用以下内容:

<Row>
  <Cell ss:StyleID="s1">
    <ss:Data ss:Type="String" xml:space="preserve" xlmns="http://www.w3.org/TR/REC-html40"><Font>Black text</Font><B>Bold text</B><Font html:Color="#FF0000">Red text</Font></ss:Data>
  </Cell>
</Row>

不幸的是,这似乎没有任何效果。当我在 Excel 中打开时,我的文本显示为全黑且非粗体。

我完全被难住了,因为我认为 &lt;Font html:Color="#FF0000"&gt;Red text&lt;/Font&gt;&lt;B&gt;Bold text&lt;/B&gt; 是正确使用的元素。

这是我的完整 XML:

<?xml version="1.0" encoding="utf-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office">
   <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
      <Author>John</Author>
      <LastAuthor>Smith</LastAuthor>
      <LastPrinted>2013-11-13T12:16:09Z</LastPrinted>
      <Created>2011-10-05T11:29:15Z</Created>
      <LastSaved>2014-02-03T15:36:18Z</LastSaved>
      <Company>Microsoft</Company>
      <Version>14.00</Version>
   </DocumentProperties>
   <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
      <AllowPNG/>
   </OfficeDocumentSettings>
   <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
      <WindowHeight>9096</WindowHeight>
      <WindowWidth>22980</WindowWidth>
      <WindowTopX>0</WindowTopX>
      <WindowTopY>252</WindowTopY>
      <ProtectStructure>False</ProtectStructure>
      <ProtectWindows>False</ProtectWindows>
   </ExcelWorkbook>

   <Styles>
      <Style xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:ID="s1">
         <Alignment ss:Vertical="Top" ss:WrapText="1"/>
         <Borders>
            <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
            <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
            <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
            <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
         </Borders>
         <Font xmlns:x="urn:schemas-microsoft-com:office:excel" ss:FontName="Calibri" x:Family="Swiss" ss:Size="11"/>
      </Style>
   </Styles>

   <Worksheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ss:Name="PDA Printout">
      <Table xmlns:x="urn:schemas-microsoft-com:office:excel">
         <Column ss:Width="500"/>
         <Row>
            <Cell ss:StyleID="s1">
               <ss:Data ss:Type="String" xml:space="preserve" xlmns="http://www.w3.org/TR/REC-html40"><Font>Black text</Font><B>Bold text</B><Font Color="#FF0000">Red text</Font></ss:Data>
            </Cell>
         </Row>
      </Table>
   </Worksheet>

</Workbook>

【问题讨论】:

    标签: xml excel


    【解决方案1】:

    似乎有可能。你刚才打错字了。 :)

    将 xlmns 更改为 xmlns

    【讨论】:

    • 感谢您的评论,但我可以确认 Excel确实在单个单元格中支持多种样式。这可以通过创建一个新的 Excel 文件、在单个单元格中应用多种样式然后保存为 XML 电子表格 2003 来证明。
    • @CraigJohnstone 嘿,你是对的。我会删除这个错误的答案,并尝试看看它为什么不适合你。
    • @CraigJohnstone 改变了答案。请尝试一下。我刚刚保存了一个具有不同格式的文件并复制了差异。 :)
    • @CraigJohnstone 啊,你刚才打错了。但我认为最好保留这个问题,因为当我搜索它时,很多人说这是不可能的。
    • 因为一个错字在桌子上敲了好几个小时!谢谢你的帮助:)
    猜你喜欢
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多