[% USE date %]
<workbook>
  [% IF data %][% size = data.size + 1 %][% END %]
  <worksheet name='Comments' autofilter='A1:[% last_col %][% size %]'>
    <row>
      <format bold='1' bg_color='silver' align='center'>
        [% FOREACH col = columns %]
        [% IF    col == "Hostname"   %]<cell width='30'>Hostname</cell>
        [% ELSIF col == "Service"    %]<cell width='30'>Service</cell>
        [% ELSIF col == "Site"       %]<cell width='30'>Site</cell>
        [% ELSIF col == "Entry Time" %]<cell width='20'>Entry Time</cell>
        [% ELSIF col == "Author"     %]<cell width='16'>Author</cell>
        [% ELSIF col == "Comment"    %]<cell width='40'>Comment</cell>
        [% ELSIF col == "Comment ID" %]<cell width='10'>Comment ID</cell>
        [% ELSIF col == "Persistent" %]<cell width='10'>Persistent</cell>
        [% ELSIF col == "Type"       %]<cell width='14'>Type</cell>
        [% ELSIF col == "Expires"    %]<cell width='20'>Expires</cell>
        [% END %]
        [% END %]
      </format>
    </row>
    [% FOREACH d = data %]
      <row>
        [% FOREACH col = columns %]
        [% IF    col == "Hostname"   %]<cell>[% escape_xml(d.host_name) %]</cell>
        [% ELSIF col == "Service"    %]<cell>[% escape_xml(d.service_description) %]</cell>
        [% ELSIF col == "Site"       %]<cell>[% escape_xml(peer_name(d)) %]</cell>
        [% ELSIF col == "Entry Time" %]<format num_format='yyyy-mm-dd hh:mm:ss'><cell>[% format_date(d.entry_time, '%Y-%m-%dT%H:%M:%S') %]</cell></format>
        [% ELSIF col == "Author"     %]<cell>[% escape_xml(d.author) %]</cell>
        [% ELSIF col == "Comment"    %]<cell>[% escape_xml(d.comment) %]</cell>
        [% ELSIF col == "Comment ID" %]<cell>[% d.id %]</cell>
        [% ELSIF col == "Persistent" %]<cell>[% IF d.persistent %]Yes[% ELSE %]No[% END %]</cell>
        [% ELSIF col == "Type"       %]<cell>[% IF d.entry_type == 1 %]User[% ELSIF d.entry_type == 2 %]Scheduled Downtime[% ELSIF d.entry_type == 3 %]Flap Detection[% ELSIF d.entry_type == 4 %]Acknowledgement[% ELSE %]?[% END %]</cell>
        [% ELSIF col == "Expires"    %][% IF d.expires %]<format num_format='yyyy-mm-dd hh:mm:ss'><cell>[% format_date(d.expire_time, '%Y-%m-%dT%H:%M:%S') %]</cell></format>[% ELSE %]<cell>N/A</cell>[% END %]
        [% END %]
        [% END %]
      </row>
    [% END %]
  </worksheet>
</workbook>
