Почему я не могу открыть открытый XML (созданный в Ruby on Rails) с помощью программного обеспечения Excel? - PullRequest
1 голос
/ 29 марта 2019

Я использовал шаблон xlsx.erb в своем приложении Rails для генерации отчета Excel (в виде офисного XML).Файл Excel генерируется нормально, но я получаю сообщение об ошибке при открытии его в программном обеспечении Excel (extension or file format maybe be invalid)

Это шаблон, который я использовал для создания открытого XML Excel:

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Forecast">
<Names>
<NamedRange ss:Name="Print_Area"/>
</Names>
<Table>
  <Row>
    <% (1..5).each do |dayi| %>
      <Cell><Data ss:Type="String"><%= 'Day' + dayi.to_s %></Data><NamedCell
  ss:Name="pRange_default"/><NamedCell ss:Name="Print_Area"/></Cell>
    <% end %>

    <Cell/>

    <% (25..30).each do |i| %>
      <Cell><Data ss:Type="String"><%= 'NP' + i.to_s %></Data></Cell>
    <% end %>
  </Row>

  <% (1..5).each do |rowi| %>
    <Row>
      <% (1..5).each do |ci| %>
        <Cell><Data><%= ci %></Data><NamedCell
  ss:Name="pRange_default"/><NamedCell ss:Name="Print_Area"/></Cell>
      <% end %>

      <Cell/>

      <% (25..30).each do |i| %>
        <Cell><Data><%= i %></Data></Cell>
      <% end %>
    </Row>
  <% end %>
</Table>
</Worksheet>
</Workbook>

Этосгенерированный открытый XML:

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
  <Worksheet ss:Name="Forecast">
  <Names>
   <NamedRange ss:Name="Print_Area"/>
  </Names>
    <Table>
      <Row>
          <Cell>    <Data ss:Type="String">Day1    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
          <Cell>    <Data ss:Type="String">Day2    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
          <Cell>    <Data ss:Type="String">Day3    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
          <Cell>    <Data ss:Type="String">Day4    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
          <Cell>    <Data ss:Type="String">Day5    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>

        <Cell/>

          <Cell>    <Data ss:Type="String">NP25    </Data>    </Cell>
          <Cell>    <Data ss:Type="String">NP26    </Data>    </Cell>
          <Cell>    <Data ss:Type="String">NP27    </Data>    </Cell>
          <Cell>    <Data ss:Type="String">NP28    </Data>    </Cell>
          <Cell>    <Data ss:Type="String">NP29    </Data>    </Cell>
          <Cell>    <Data ss:Type="String">NP30    </Data>    </Cell>
      </Row>

        <Row>
            <Cell>    <Data>1    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>2    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>3    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>4    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>5    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>

          <Cell/>

            <Cell>    <Data>25    </Data>    </Cell>
            <Cell>    <Data>26    </Data>    </Cell>
            <Cell>    <Data>27    </Data>    </Cell>
            <Cell>    <Data>28    </Data>    </Cell>
            <Cell>    <Data>29    </Data>    </Cell>
            <Cell>    <Data>30    </Data>    </Cell>
        </Row>
        <Row>
            <Cell>    <Data>1    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>2    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>3    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>4    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>5    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>

          <Cell/>

            <Cell>    <Data>25    </Data>    </Cell>
            <Cell>    <Data>26    </Data>    </Cell>
            <Cell>    <Data>27    </Data>    </Cell>
            <Cell>    <Data>28    </Data>    </Cell>
            <Cell>    <Data>29    </Data>    </Cell>
            <Cell>    <Data>30    </Data>    </Cell>
        </Row>
        <Row>
            <Cell>    <Data>1    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>2    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>3    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>4    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>5    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>

          <Cell/>

            <Cell>    <Data>25    </Data>    </Cell>
            <Cell>    <Data>26    </Data>    </Cell>
            <Cell>    <Data>27    </Data>    </Cell>
            <Cell>    <Data>28    </Data>    </Cell>
            <Cell>    <Data>29    </Data>    </Cell>
            <Cell>    <Data>30    </Data>    </Cell>
        </Row>
        <Row>
            <Cell>    <Data>1    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>2    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>3    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>4    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>5    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>

          <Cell/>

            <Cell>    <Data>25    </Data>    </Cell>
            <Cell>    <Data>26    </Data>    </Cell>
            <Cell>    <Data>27    </Data>    </Cell>
            <Cell>    <Data>28    </Data>    </Cell>
            <Cell>    <Data>29    </Data>    </Cell>
            <Cell>    <Data>30    </Data>    </Cell>
        </Row>
        <Row>
            <Cell>    <Data>1    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>2    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>3    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>4    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>
            <Cell>    <Data>5    </Data>    <NamedCell
  ss:Name="pRange_default"/>    <NamedCell ss:Name="Print_Area"/>    </Cell>

          <Cell/>

            <Cell>    <Data>25    </Data>    </Cell>
            <Cell>    <Data>26    </Data>    </Cell>
            <Cell>    <Data>27    </Data>    </Cell>
            <Cell>    <Data>28    </Data>    </Cell>
            <Cell>    <Data>29    </Data>    </Cell>
            <Cell>    <Data>30    </Data>    </Cell>
        </Row>
    </Table>
  </Worksheet>
</Workbook>

Почему я не могу открыть открытое выше XML с помощью программного обеспечения Excel?

Пожалуйста, помогите!

...