0

enter image description hereI'm making a report where it would show the data of the incidents happened in a month. There are 4 options per incident that happened. What do I need to do to get all the 4 selected values in every incident and export the whole table including the selected values to excel?

I tried the php form handling but I can't make it work also javascrip. but I can't make the values selected show.

// PHP

 for ($i=0; $i < count($dates); $i++) { 
     echo " 
           <tr>
                  <td>$tripdate[$i]</td>
                  <td contenteditable='true'></td>
                  <td>$cicuitNumber[$i]</td>
                  <td>$triptime[$i]</td>
                  <td>$dates[$i]</td>
                  <td>$dates1[$i]</td>
                  <td>$dates2[$i]</td>
                  <td contenteditable='true'> </td> 

    ////////////// OPTION#1 ///////////////////

                  <td>           
                     <div class='form-group'>
                       <select class='form-control' id='InterruptionCause' name='InterruptionCause' >
                          <option value ='0' selected>0</option>
                          <option value='001'>001</option>
                          <option value='002'>002</option>
                          <option value='003'>003</option>
                          <option value='004'>004</option>
                       </select>
                    </div>
                  </td>


    ////////////// OPTION#2 ///////////////////

                  <td>
                    <div class='form-group'>
                       <select class='form-control' id='InterruptionWeather'>
                         <option value='101'>101</option>
                         <option value='102'>102</option>
                         <option value='103'>103</option>

                      </select>
                    </div>
                 </td>

    ///////////// OPTION#3 //////////////

                 <td>
                    <div class='form-group'>
                       <select class='form-control' id='InterruptionDevice'>
                         <option value='201'>201</option>
                         <option value='202'>202</option>
                         <option value='203'>203</option>
                        </select>
                    </div>
                </td>


    ///////////// OPTION#4 /////////////

                <td>
                   <div class='form-group'>
                       <select class='form-control' id='InterruptionEquipment'  >

                          <optionvalue='301'>301</option>
                          <option value='302'>302</option>
                          <option value='303'>303</option>
                          <option value='304'>304</option>
                           <option value='305'>305</option>
                        </select>
                    </div>
                </td>                     
       </tr>
                            ";

                            }

// Exporting to excel

    function fnExcelReport() {
           var tab_text = '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
           tab_text = tab_text + '<head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>';



tab_text = tab_text + '<x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet>';
tab_text = tab_text + '</x:ExcelWorksheets></x:ExcelWorkbook></xml></head><body>';

tab_text = tab_text + "<table border='1px'>";

tab_text = tab_text + $('#myTable').html();
getSelectValue();
tab_text = tab_text + '</table></body></html>';

var data_type = 'data:application/vnd.ms-excel';

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");

if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
    if (window.navigator.msSaveBlob) {
        var blob = new Blob([tab_text], {
            type: "application/csv;charset=utf-8;"
        });
        navigator.msSaveBlob(blob, '<?php echo $date." Interruption Report";?>.xls');
        // location.reload();
    }
} else {
    $('#export').attr('href', data_type + ', ' + encodeURIComponent(tab_text));
    $('#export').attr('download', '<?php echo $date." Interruption Report";?>.xls');
    // location.reload();
}
 }

I expect the output of 4 selected values of every incident to show when I export it to excel. but when I did, only the other data reflected and there are no selected values in the dropdown shows.

  • you mean you're successfully selecting the 4 results but it's not showing the selected options? – Rachel Gallen Jun 03 '19 at 09:36
  • No, I don't know how to successfully get the 4 selected options per data. when I choose the option in row 1 it will be the same selected options to the rest. – Miku Hatsune Jun 03 '19 at 09:41
  • 1
    well I'd suggest you look at [this post](https://stackoverflow.com/a/22264762/1675954) but you're going to have to define some variables for the dropdown selects and get the selected option and assign it to the variable prior to exporting. (I'm getting ready to go away for a week so I'm not much use today, but hope that helps) – Rachel Gallen Jun 03 '19 at 09:49

0 Answers0