{"id":1575,"date":"2015-12-11T12:03:06","date_gmt":"2015-12-11T11:03:06","guid":{"rendered":"http:\/\/blog.kodono.info\/wordpress\/?p=1575"},"modified":"2015-12-11T12:03:06","modified_gmt":"2015-12-11T11:03:06","slug":"excel-file-as-an-html-table-and-date-formatting","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2015\/12\/11\/excel-file-as-an-html-table-and-date-formatting\/","title":{"rendered":"Excel file as an HTML table and Date formatting"},"content":{"rendered":"<p>If you create an Excel file using an HTML Table, then it exists a way to format the cells based on some CSS rules. Some examples can be found on <a href=\"http:\/\/niallodoherty.com\/post.cfm\/basic-html-to-excel-formatting\">this blog post<\/a>.<\/p>\n<p>I spent some time trying to figure out how to display correctly the dates, whatever your regional settings are ; for exemple in the USA the format is <code>MM\/dd\/YYYY<\/code>, and for the rest of the world is <code>dd\/MM\/YYYY<\/code>.<\/p>\n<p>Finally I <a href=\"http:\/\/stackoverflow.com\/a\/25568552\/1134119\">found<\/a> that the content of the date cells must always be defined with the same format : <code>YYY-MM-dd HH:mm<\/code>, and then we can apply a style like <code>mso-number-format:\"dd\\-mmm\\-yyyy\\ hh\\:mm\"<\/code>.<\/p>\n<p>Example:<\/p>\n<pre class=\"brush:html\">\r\n&lt;html>\r\n&lt;head>\r\n&lt;style>br {mso-data-placement:same-cell} .xls-date {mso-number-format:\"dd-mmm-yyyy hh:mm\"}&lt;\/style>\r\n&lt;\/head>\r\n&lt;body>\r\n  &lt;table>\r\n    &lt;tr>\r\n      &lt;th>Event Name&lt;\/th>\r\n      &lt;th>Event Date&lt;\/th>\r\n    &lt;\/tr>\r\n    &lt;tr>\r\n      &lt;td>Birthday Party&lt;\/td>\r\n      &lt;td class=\"xls-date\">2015-11-01 10:00&lt;\/td>\r\n    &lt;\/tr>\r\n  &lt;\/table>\r\n&lt;\/html>\r\n<\/pre>\n<p>So the date cell will display: <code>01-Nov-2015 10:00<\/code> and will be interpreted as a Date cell by Excel.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you create an Excel file using an HTML Table, then it exists a way to format the cells based on some CSS rules. Some examples can be found on this blog post. I spent some time trying to figure out how to display correctly the dates, whatever your regional settings are ; for exemple [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[13,33,8],"tags":[167,152,158,148],"class_list":["post-1575","post","type-post","status-publish","format-standard","hentry","category-niveau-intermediaire","category-programmation","category-windows","tag-excel","tag-niveau-intermediaire","tag-programmation","tag-windows"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1575"}],"version-history":[{"count":4,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1575\/revisions"}],"predecessor-version":[{"id":1579,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1575\/revisions\/1579"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}