HTML to Excel: How can tell Excel to treat columns as numbers?

前端 未结 7 977
半阙折子戏
半阙折子戏 2020-12-04 18:42

I need to achieve the following when opening an HTML in Excel (Response.contentType=\"application/vnd.ms-excel\") :

  • force Excel to consider conten
相关标签:
7条回答
  • 2020-12-04 18:42
    mso-number-format:0         NO Decimals
    mso-number-format:"\#\,\#\#0\.000" 3 Decimals 
    mso-number-format:"mm\/dd\/yy" Thousand comma with 3 decimals  
    mso-number-format:"mmmm\\ d\\\,\\ yyyy" Date7 
    mso-number-format:"m\/d\/yy\\ h\:mm\\ AM\/PM" Date9 
    

    Text Column

    "<td style=\"mso-number-format:'\@'\">"
    

    or

    <td style="mso-number-format:'\@'">
    
    0 讨论(0)
  • 2020-12-04 18:46

    It doesn't works sometimes if you add it using a css class in that case try it using in Style to your TD. I did it for formatting a column to a text. like this

     style="mso-number-format:\@;"
    

    For you it would be as

      mso-number-format:General
    
    0 讨论(0)
  • 2020-12-04 18:48

    UPDATE: You also need to remove non-breaking spaces (nbsp's) from td cells containing numeric or money information to make formulas work on these cells in Excel. So the problem is solved.

    0 讨论(0)
  • 2020-12-04 18:50

    I couldn't get any of the answers on this page to work in Excel 2010. I ended up using this.

    <td x:num>123</td>

    0 讨论(0)
  • 2020-12-04 18:58

    If you add a CSS Class to your page:

    .num {
      mso-number-format:General;
    }
    .date {
      mso-number-format:"Short Date";
    }
    

    And slap those classes on your TD's, does it work?

    <td class="num">34</td>
    <td class="num">17.0</td>
    <td class="date">12/17/2008</td> <!-- if you are playing with dates too -->
    

    Update: Additional formatting options from @Aaron.

    0 讨论(0)
  • 2020-12-04 19:08

    Here is a list of Excel formats: Styling Excel cells with mso-number-format

    0 讨论(0)
提交回复
热议问题