简体   繁体   中英

Get HTML table values for excel export - from: input.value

I have a table in HTML that I need to convert into excel to complete an order to be sent as eMail attachment.

The table itself is a basket for orders. The client adds the products, the page loads more details from the database (most of the HTML table code is produced in C#). Some Javascript to update the total based on the quantity, etc.

Problem is that for my order report I need to extract all info from different scenarios. Some info is inside the tag, some other is in the “value” propertie and some is modified with javascript.

Most examples in stackOverflow are about getting the info from the tag and totally impossible to adapt to my need.

I have already rebuilt the code for this specific page twice so I wouldn't be surprised if someone says the structure is all wrong and I need to do it another way.

Am I using inputs wrong?

<table id="tableReport" class="tablePanier">
  <tbody>
    <tr>
      <th class="titles">GenCod</th>
      <th class="titles">Auteur</th>
      <th class="titles">Titre</th>
      <th class="titles">Quantite</th>
      <th class="titles">PrixTTC</th>
      <th class="titles">TotalPrixTTC</th>
      <th class="titles">Delete</th>
    </tr>
    <tr class="line_hover">
      <td>9782871428374</td>
      <td>WARNES, TIM</td>
      <td>FICHU CANETON</td>
      <td>
        <input
          id="Quantity9782871428374"
          onclick="ReCalculateTotal(9782871428374)"
          value="1"
          min="1"
          type="number"
          name="fname"
          style=" width: 100px;  text-align: center; "
        />
      </td>
      <td id="Prix_TTC">
        <input
          id="Prix_TTC9782871428374"
          type="text"
          value="5.2"
          name="Prix_TTC"
          style=" width: 100px;  text-align: center; "
          disabled=""
        />
      </td>
      <td>
        <input
          id="Total9782871428374"
          type="text"
          name="fname"
          value="5.2"
          style=" width: 100px;  text-align: center; "
          disabled=""
        />
      </td>
      <td>
        <a href="../panierdecommande.aspx?remove=9782871428374">
          <input
            type="button"
            value="Retirer"
            name="fname"
            style=" width: 100px;  text-align: center; "
        /></a>
      </td>
    </tr>
    <tr class="line_hover">
      <td>9791021406605</td>
      <td>Cuenca, Catherine</td>
      <td>REINE MARGOT (LA)</td>
      <td>
        <input
          id="Quantity9791021406605"
          onclick="ReCalculateTotal(9791021406605)"
          value="1"
          min="1"
          type="number"
          name="fname"
          style=" width: 100px;  text-align: center; "
        />
      </td>
      <td id="Prix_TTC">
        <input
          id="Prix_TTC9791021406605"
          type="text"
          value="12.95"
          name="Prix_TTC"
          style=" width: 100px;  text-align: center; "
          disabled=""
        />
      </td>
      <td>
        <input
          id="Total9791021406605"
          type="text"
          name="fname"
          value="12.95"
          style=" width: 100px;  text-align: center; "
          disabled=""
        />
      </td>
      <td>
        <a href="../panierdecommande.aspx?remove=9791021406605">
          <input
            type="button"
            value="Retirer"
            name="fname"
            style=" width: 100px;  text-align: center; "
        /></a>
      </td>
    </tr>
    <tr class="line_hover">
      <td>9782371262737</td>
      <td>Stone, Liv</td>
      <td>Initie-moi. Mes jours contre tes nuits</td>
      <td>
        <input
          id="Quantity9782371262737"
          onclick="ReCalculateTotal(9782371262737)"
          value="1"
          min="1"
          type="number"
          name="fname"
          style=" width: 100px;  text-align: center; "
        />
      </td>
      <td id="Prix_TTC">
        <input
          id="Prix_TTC9782371262737"
          type="text"
          value="14.9"
          name="Prix_TTC"
          style=" width: 100px;  text-align: center; "
          disabled=""
        />
      </td>
      <td>
        <input
          id="Total9782371262737"
          type="text"
          name="fname"
          value="14.9"
          style=" width: 100px;  text-align: center; "
          disabled=""
        />
      </td>
      <td>
        <a href="../panierdecommande.aspx?remove=9782371262737">
          <input
            type="button"
            value="Retirer"
            name="fname"
            style=" width: 100px;  text-align: center; "
        /></a>
      </td>
    </tr>
  </tbody>
</table>

You can use jquery datatable for solution

For example: https://datatables.net/extensions/buttons/examples/initialisation/export.html

You can trigger the standard button if you want. Call DataTables export functions from JavaScript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM