Home > database >  Parse HTML Table and hide columns
Parse HTML Table and hide columns

Time:05-19

I have this basic HTML table that I export from JIRA. I need a quick way to hide all columns and show only 2 columns (Key Summary).

Please see the image below.

enter image description here

I know that there will be more than one way to skin this cat like python, nodejs, and even PHP. But I'm looking for the best fastest & lightest way to achieve it, I was thinking JS since we all have access to it directly in our Console so

const someStyle = `
<style>
    th  { display:none; }
    th:nth-child(2),th:nth-child(4)  { display:block; }
</style>
`;


document.head.insertAdjacentHTML('beforeend', someStyle);

This doesn't work.


#HTML

<html xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:x="urn:schemas-microsoft-com:office:excel"
      xmlns="http://www.w3.org/TR/REC-html40">
    <head>
        <title>John's Done  (Apple Project Management)</title>
        <style type="text/css">
         table {
             mso-displayed-decimal-separator:"\.";
             mso-displayed-thousand-separator:"\,";
         }
         body
         {
             margin: 0px;
             font-size: 12px;
             font-family: Arial, sans-serif;
             color:black;
         }

        </style>
        <META HTTP-EQUIV="Content-Type" Content="application/vnd.ms-excel; charset=UTF-8">
        <!-- JRA-7598 - ensure fields (e.g. description) occupy only one cell - even fields containing newlines. -->
        <!--
             Vertical align all cells to the top, in order to align all issue rows of issuetable to the top,
             since Excel does not use or save the css files it is hardcoded here.
           -->
        <style>
         @page
         {
             mso-page-orientation:landscape;
             margin:.25in .25in .5in .25in;
             mso-header-margin:.5in;
             mso-footer-margin:.25in;
             mso-footer-data:"&R&P of &N";
             mso-horizontal-page-align:center;
             mso-vertical-page-align:center;
         }

         td.issuekey,
         td.issuetype,
         td.status {
             mso-style-parent: "";
             mso-number-format: \@;
             text-align: left;
         }
         br
         {
             mso-data-placement:same-cell;
         }

         td
         {
             vertical-align: top;
         }
        </style>

        <!--[if gte mso 9]><xml>
            <x:ExcelWorkbook>
            <x:ExcelWorksheets>
            <x:ExcelWorksheet>
            <x:Name>general_report</x:Name>
            <x:WorksheetOptions>
            <x:Print>
            <x:ValidPrinterInfo/>
            </x:Print>
            </x:WorksheetOptions>
            </x:ExcelWorksheet>
            </x:ExcelWorksheets>
            </x:ExcelWorkbook>
            </xml><![endif]-->
    </head>
    <body>

        <table border="1">
            <tr bgcolor="#0747a6" height="30">
                <td colspan="11">
                    <img src="http://dev.apple.local:1234/images/jira-software.png" width="57" height="30" border="0" alt="John's Done  (Apple Project Management)">
                </td>
            </tr>
            <tr>
                <td colspan="11">
                    <a href="http://dev.apple.local:1234/issues/?filter=11526">John's Done  (Apple Project Management)</a>
                </td>
            </tr>
            <tr>
                <td colspan="11">
                    Displaying <strong>3</strong> issues at <strong>18/May/22 12:56 PM</strong>.
                </td>
            </tr>
        </table>

        


                            <issuetable-web-component data-content="issues">
                <table id="issuetable"  border="1" cellpadding="3" cellspacing="1" width="100%">
                        <thead>
        <tr >
            
                                                            <th  data-id="issuetype">
                            Issue Type
                                                    </th>
                                                
                                                            <th  data-id="priority">
                            Priority
                                                    </th>
                                                
                                                            <th  data-id="issuekey">
                            Key
                                                    </th>
                                                
                                                            <th  data-id="status">
                            Status
                                                    </th>
                                                
                                                            <th  data-id="summary">
                            Summary
                                                    </th>
                                                
                                                            <th  data-id="assignee">
                            Assignee
                                                    </th>
                                                
                                                            <th  data-id="customfield_10100">
                            Sprint
                                                    </th>
                                                
                                                            <th  data-id="issuelinks">
                            Linked Issues
                                                    </th>
                                                
                                                            <th  data-id="customfield_10101">
                            Epic Link
                                                    </th>
                                                
                                                            <th  data-id="updated">
                            Updated
                                                    </th>
                                                
                                                            <th  data-id="duedate">
                            Due Date
                                                    </th>
                                                                    </tr>
    </thead>
    <tbody>
                    

                <tr id="issuerow14995" rel="14995" data-issuekey="TI-325" >
                                            <td >    Bug
</td>
                                            <td >           High
    </td>
                                            <td >

    <a  data-issue-key="TI-325" href="http://dev.apple.local:1234/browse/TI-325">TI-325</a>
</td>
                                            <td >
                <span  data-tooltip="&lt;span class=&quot;jira-issue-status-tooltip-title&quot;&gt;Awaiting QA&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;jira-issue-status-tooltip-desc&quot;&gt;Awiting QA approval is defined as the QA manager has tested based on the feature requirements.  During this phase the reporter/business contact that requested this feature needs to also test and sign off on the feature.&lt;/span&gt;">Awaiting QA</span>    </td>
                                            <td ><p>
                Campaign - All Types - Values Not Being Passed on the UI (Export Factory XF Date)
    </p>
</td>
                                            <td >            John Heng
    </td>
                                            <td ></td>
                                            <td >                </td>
                                            <td >
            Bug Tracker - Go To Market May Release 2022
    </td>
                                            <td > 18/May/22 12:34 AM </td>
                                            <td >    &nbsp;
</td>
                    </tr>


                <tr id="issuerow14993" rel="14993" data-issuekey="TI-324" >
                                            <td >    Bug
</td>
                                            <td >           Medium
    </td>
                                            <td >

    <a  data-issue-key="TI-324" href="http://dev.apple.local:1234/browse/TI-324">TI-324</a>
</td>
                                            <td >
                <span  data-tooltip="&lt;span class=&quot;jira-issue-status-tooltip-title&quot;&gt;Awaiting QA&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;jira-issue-status-tooltip-desc&quot;&gt;Awiting QA approval is defined as the QA manager has tested based on the feature requirements.  During this phase the reporter/business contact that requested this feature needs to also test and sign off on the feature.&lt;/span&gt;">Awaiting QA</span>    </td>
                                            <td ><p>
                Campaign - Edit Page - Rules Parameters DO NOT DISPLAY CORRECTLY
    </p>
</td>
                                            <td >            John Heng
    </td>
                                            <td ></td>
                                            <td >                </td>
                                            <td >
            Bug Tracker - Go To Market May Release 2022
    </td>
                                            <td > 18/May/22 12:36 AM </td>
                                            <td >    &nbsp;
</td>
                    </tr>


                <tr id="issuerow14987" rel="14987" data-issuekey="TI-318" >
                                            <td >    Bug
</td>
                                            <td >           Medium
    </td>
                                            <td >

    <a  data-issue-key="TI-318" href="http://dev.apple.local:1234/browse/TI-318">TI-318</a>
</td>
                                            <td >
                <span  data-tooltip="&lt;span class=&quot;jira-issue-status-tooltip-title&quot;&gt;Awaiting QA&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;jira-issue-status-tooltip-desc&quot;&gt;Awiting QA approval is defined as the QA manager has tested based on the feature requirements.  During this phase the reporter/business contact that requested this feature needs to also test and sign off on the feature.&lt;/span&gt;">Awaiting QA</span>    </td>
                                            <td ><p>
                Rule Conditions have filled colored cells on Product and Marketing Campaign Detail
    </p>
</td>
                                            <td >            John Heng
    </td>
                                            <td >CE Go To Market Sprint</td>
                                            <td >                </td>
                                            <td >
            Bug Tracker - Go To Market May Release 2022
    </td>
                                            <td > 18/May/22 12:53 PM </td>
                                            <td >    20/May/22
</td>
                    </tr>
                </tbody>
    </table>
    </issuetable-web-component>
    <div ></div>
            <table border="1" >
<tr>
    <td bgcolor="#f5f5f5" colspan="11"><font size="1">
        Generated at Wed May 18 12:56:37 UTC 2022 by John Heng using Jira 8.12.1#812002-sha1:7c28d59557fed9c1e3e470d7ce83e486c2b409b6.
    </font></td>
</tr>
</table>

</body>
</html>

CodePudding user response:

There is a few mistakes, td are not minded and th/td default display is table-cell ;)

Here is how i would do: (create a style element,innerHTML style to it and then append it to head)

const someStyle = `
    #issuetable th ,#issuetable td,
    table:not([id]) { display:none; }
    #issuetable th:nth-child(2),#issuetable th:nth-child(5),
    #issuetable td:nth-child(2),#issuetable td:nth-child(5){ display:table-cell; }
`;
let style = document.createElement('style');
style.innerHTML = someStyle;
document.head.appendChild(style);
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

<head>
  <title>John's Done (Apple Project Management)</title>
  <style type="text/css">
    table {
      mso-displayed-decimal-separator: "\.";
      mso-displayed-thousand-separator: "\,";
    }
    
    body {
      margin: 0px;
      font-size: 12px;
      font-family: Arial, sans-serif;
      color: black;
    }
  </style>
  <META HTTP-EQUIV="Content-Type" Content="application/vnd.ms-excel; charset=UTF-8">
  <!-- JRA-7598 - ensure fields (e.g. description) occupy only one cell - even fields containing newlines. -->
  <!--
             Vertical align all cells to the top, in order to align all issue rows of issuetable to the top,
             since Excel does not use or save the css files it is hardcoded here.
           -->
  <style>
    @page {
      mso-page-orientation: landscape;
      margin: .25in .25in .5in .25in;
      mso-header-margin: .5in;
      mso-footer-margin: .25in;
      mso-footer-data: "&R&P of &N";
      mso-horizontal-page-align: center;
      mso-vertical-page-align: center;
    }
    
    td.issuekey,
    td.issuetype,
    td.status {
      mso-style-parent: "";
      mso-number-format: \@;
      text-align: left;
    }
    
    br {
      mso-data-placement: same-cell;
    }
    
    td {
      vertical-align: top;
    }
  </style>

  <!--[if gte mso 9]><xml>
            <x:ExcelWorkbook>
            <x:ExcelWorksheets>
            <x:ExcelWorksheet>
            <x:Name>general_report</x:Name>
            <x:WorksheetOptions>
            <x:Print>
            <x:ValidPrinterInfo/>
            </x:Print>
            </x:WorksheetOptions>
            </x:ExcelWorksheet>
            </x:ExcelWorksheets>
            </x:ExcelWorkbook>
            </xml><![endif]-->
</head>

<body>

  <table border="1">
    <tr bgcolor="#0747a6" height="30">
      <td colspan="11">
        <img src="http://dev.apple.local:1234/images/jira-software.png" width="57" height="30" border="0" alt="John's Done  (Apple Project Management)">
      </td>
    </tr>
    <tr>
      <td colspan="11">
        <a href="http://dev.apple.local:1234/issues/?filter=11526">John's Done  (Apple Project Management)</a>
      </td>
    </tr>
    <tr>
      <td colspan="11">
        Displaying <strong>3</strong> issues at <strong>18/May/22 12:56 PM</strong>.
      </td>
    </tr>
  </table>




  <issuetable-web-component data-content="issues">
    <table id="issuetable" border="1" cellpadding="3" cellspacing="1" width="100%">
      <thead>
        <tr >

          <th  data-id="issuetype">
            Issue Type
          </th>

          <th  data-id="priority">
            Priority
          </th>

          <th  data-id="issuekey">
            Key
          </th>

          <th  data-id="status">
            Status
          </th>

          <th  data-id="summary">
            Summary
          </th>

          <th  data-id="assignee">
            Assignee
          </th>

          <th  data-id="customfield_10100">
            Sprint
          </th>

          <th  data-id="issuelinks">
            Linked Issues
          </th>

          <th  data-id="customfield_10101">
            Epic Link
          </th>

          <th  data-id="updated">
            Updated
          </th>

          <th  data-id="duedate">
            Due Date
          </th>
        </tr>
      </thead>
      <tbody>


        <tr id="issuerow14995" rel="14995" data-issuekey="TI-325" >
          <td > Bug
          </td>
          <td > High
          </td>
          <td >

            <a  data-issue-key="TI-325" href="http://dev.apple.local:1234/browse/TI-325">TI-325</a>
          </td>
          <td >
            <span  data-tooltip="&lt;span class=&quot;jira-issue-status-tooltip-title&quot;&gt;Awaiting QA&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;jira-issue-status-tooltip-desc&quot;&gt;Awiting QA approval is defined as the QA manager has tested based on the feature requirements.  During this phase the reporter/business contact that requested this feature needs to also test and sign off on the feature.&lt;/span&gt;">Awaiting QA</span>            </td>
          <td >
            <p>
              Campaign - All Types - Values Not Being Passed on the UI (Export Factory XF Date)
            </p>
          </td>
          <td > John Heng
          </td>
          <td ></td>
          <td > </td>
          <td >
            Bug Tracker - Go To Market May Release 2022
          </td>
          <td > 18/May/22 12:34 AM </td>
          <td > &nbsp;
          </td>
        </tr>


        <tr id="issuerow14993" rel="14993" data-issuekey="TI-324" >
          <td > Bug
          </td>
          <td > Medium
          </td>
          <td >

            <a  data-issue-key="TI-324" href="http://dev.apple.local:1234/browse/TI-324">TI-324</a>
          </td>
          <td >
            <span  data-tooltip="&lt;span class=&quot;jira-issue-status-tooltip-title&quot;&gt;Awaiting QA&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;jira-issue-status-tooltip-desc&quot;&gt;Awiting QA approval is defined as the QA manager has tested based on the feature requirements.  During this phase the reporter/business contact that requested this feature needs to also test and sign off on the feature.&lt;/span&gt;">Awaiting QA</span>            </td>
          <td >
            <p>
              Campaign - Edit Page - Rules Parameters DO NOT DISPLAY CORRECTLY
            </p>
          </td>
          <td > John Heng
          </td>
          <td ></td>
          <td > </td>
          <td >
            Bug Tracker - Go To Market May Release 2022
          </td>
          <td > 18/May/22 12:36 AM </td>
          <td > &nbsp;
          </td>
        </tr>


        <tr id="issuerow14987" rel="14987" data-issuekey="TI-318" >
          <td > Bug
          </td>
          <td > Medium
          </td>
          <td >

            <a  data-issue-key="TI-318" href="http://dev.apple.local:1234/browse/TI-318">TI-318</a>
          </td>
          <td >
            <span  data-tooltip="&lt;span class=&quot;jira-issue-status-tooltip-title&quot;&gt;Awaiting QA&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;jira-issue-status-tooltip-desc&quot;&gt;Awiting QA approval is defined as the QA manager has tested based on the feature requirements.  During this phase the reporter/business contact that requested this feature needs to also test and sign off on the feature.&lt;/span&gt;">Awaiting QA</span>            </td>
          <td >
            <p>
              Rule Conditions have filled colored cells on Product and Marketing Campaign Detail
            </p>
          </td>
          <td > John Heng
          </td>
          <td >CE Go To Market Sprint</td>
          <td > </td>
          <td >
            Bug Tracker - Go To Market May Release 2022
          </td>
          <td > 18/May/22 12:53 PM </td>
          <td > 20/May/22
          </td>
        </tr>
      </tbody>
    </table>
  </issuetable-web-component>
  <div ></div>
  <table border="1">
    <tr>
      <td bgcolor="#f5f5f5" colspan="11">
        <font size="1">
          Generated at Wed May 18 12:56:37 UTC 2022 by John Heng using Jira 8.12.1#812002-sha1:7c28d59557fed9c1e3e470d7ce83e486c2b409b6.
        </font>
      </td>
    </tr>
  </table>

</body>

</html>

  • Related