2015-09-14 14 views
10

Voglio sapere se abbiamo una soluzione jquery o javascript per convertire la tabella html in powerpoint. Solo la soluzione che ho ottenuto è html table export. Qui abbiamo tutte le opzioni di esportazione ma voglio la soluzione solo per powerpoint. Posso usare l'esportazione della tabella Html ma la mia preoccupazione è che, per un export, dovrei usare un intero plugin. Esiste un codice di esempio solo per ppt?Esporta la tabella html su ppt sul lato client?

+0

io suggerirei al meglio lato l'utilizzo del server per questo. –

+0

@OscarJara Perché sovraccaricare il server quando è possibile delegare parte dell'elaborazione al client? Il server genera una tabella HTML, che è un carico abbastanza leggero, ma se deve offrire il download di un documento, il caricamento dei dati dal server aumenta inutilmente. Poiché non si tratta di una violazione della sicurezza, è abbastanza ragionevole esportare il formato sul lato client. –

risposta

6

Se la dimensione della libreria è una preoccupazione per voi, la soluzione migliore potrebbe essere quella di modificare la libreria js da soli. Estrazione di parti di codice che potrebbero non essere correlate alle funzioni del punto di alimentazione. E poi testare, rendendo progressivamente la libreria sempre più piccola. Oltre a questo, non ho trovato alcun ovvio che abbia già questa soluzione disponibile.

Eseguendo l'esercizio di cui sopra sono stato in grado di prendere il file tableExport.js da 12kb a 5kb (non ridotto a icona) pur mantenendo l'esportazione in modalità power-point.

/*The MIT License (MIT) 

Copyright (c) 2014 https://github.com/kayalshri/ 

Permission is hereby granted.... 
.... 
*/ 

(function($){ 
    $.fn.extend({ 
     tableExport: function(options) { 
      var defaults = { 
        separator: ',', 
        ignoreColumn: [], 
        tableName:'yourTableName', 
        type:'powerpoint', 
        escape:'true', 
        htmlContent:'false', 
        consoleLog:'false' 
      }; 

      var options = $.extend(defaults, options); 
      var el = this; 

      if(defaults.type == 'powerpoint'){ 
       //console.log($(this).html()); 
       var excel="<table>"; 
       // Header 
       $(el).find('thead').find('tr').each(function() { 
        excel += "<tr>"; 
        $(this).filter(':visible').find('th').each(function(index,data) { 
         if ($(this).css('display') != 'none'){     
          if(defaults.ignoreColumn.indexOf(index) == -1){ 
           excel += "<td>" + parseString($(this))+ "</td>"; 
          } 
         } 
        }); 
        excel += '</tr>';      

       });     


       // Row Vs Column 
       var rowCount=1; 
       $(el).find('tbody').find('tr').each(function() { 
        excel += "<tr>"; 
        var colCount=0; 
        $(this).filter(':visible').find('td').each(function(index,data) { 
         if ($(this).css('display') != 'none'){ 
          if(defaults.ignoreColumn.indexOf(index) == -1){ 
           excel += "<td>"+parseString($(this))+"</td>"; 
          } 
         } 
         colCount++; 
        });               
        rowCount++; 
        excel += '</tr>'; 
       });     
       excel += '</table>' 

       if(defaults.consoleLog == 'true'){ 
        console.log(excel); 
       } 

       var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:"+defaults.type+"' xmlns='http://www.w3.org/TR/REC-html40'>"; 
       excelFile += "<head>"; 
       excelFile += "<!--[if gte mso 9]>"; 
       excelFile += "<xml>"; 
       excelFile += "<x:ExcelWorkbook>"; 
       excelFile += "<x:ExcelWorksheets>"; 
       excelFile += "<x:ExcelWorksheet>"; 
       excelFile += "<x:Name>"; 
       excelFile += "{worksheet}"; 
       excelFile += "</x:Name>"; 
       excelFile += "<x:WorksheetOptions>"; 
       excelFile += "<x:DisplayGridlines/>"; 
       excelFile += "</x:WorksheetOptions>"; 
       excelFile += "</x:ExcelWorksheet>"; 
       excelFile += "</x:ExcelWorksheets>"; 
       excelFile += "</x:ExcelWorkbook>"; 
       excelFile += "</xml>"; 
       excelFile += "<![endif]-->"; 
       excelFile += "</head>"; 
       excelFile += "<body>"; 
       excelFile += excel; 
       excelFile += "</body>"; 
       excelFile += "</html>"; 

       var base64data = "base64," + $.base64.encode(excelFile); 
       window.open('data:application/vnd.ms-'+defaults.type+';filename=exportData.doc;' + base64data); 

      } 

      function parseString(data){ 

       if(defaults.htmlContent == 'true'){ 
        content_data = data.html().trim(); 
       }else{ 
        content_data = data.text().trim(); 
       } 

       if(defaults.escape == 'true'){ 
        content_data = escape(content_data); 
       } 

       return content_data; 
      } 

     } 
    }); 
})(jQuery); 

È possibile sostituire il vostro file tableExport.js con questo codice e lo chiamano allo stesso modo passando in PowerPoint come il tipo, o si può omettere e continueranno a funzionare.

+0

Sto usando lo stesso plug-in, ma per la sua PowerPoint me che mostra i dati vuoti, anche io ho il check-in github per il rilascio: https://github.com/wenzhixin/bootstrap-table/issues/1660 Si è utilizzabile per PowerPoint, puoi guidarmi quali modifiche sono necessarie per PowerPoint. –

+0

@AlokJha scusa non ho mai usato questo plugin in realtà. Ma nel link a cui fai riferimento, sembra che il bootstrap-table avesse l'opzione PDF a un certo punto, ma non è mai stato supportato/funzionante, quindi è stato rimosso. Vedi: https://github.com/wenzhixin/bootstrap-table/commit/0679c9ed319b1629f2088cb9089acf856f4e87dd – Trevor

6

È possibile utilizzare la stessa soluzione, modificando i file JS per utilizzare solo la parte relativa a MS-Office. In realtà, la funzione che trasforma la tabella Porwerpoint è la stessa che trasforma Excel e Word.

Per fare questo, si avrebbe bisogno solo il file dijquery.base64.js, e il file tableExport.js, ma cambiando tutte le tableExport.js contenuti del seguente:

/*The MIT License (MIT) 
Copyright (c) 2014 https://github.com/kayalshri/ 
Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions: 
The above copyright notice and this permission notice shall be included in 
all copies or substantial portions of the Software. 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE SOFTWARE.*/ 

(function($){ 
     $.fn.extend({ 
      tableExport: function(options) { 
       var defaults = { 
         separator: ',', 
         ignoreColumn: [], 
         tableName:'yourTableName', 
         type:'excel', 
         escape:'true', 
         htmlContent:'false', 
         consoleLog:'false' 
       }; 

       var options = $.extend(defaults, options); 
       var el = this; 

       if(defaults.type == 'excel' || defaults.type == 'doc'|| defaults.type == 'powerpoint' ){ 
        //console.log($(this).html()); 
        var excel="<table>"; 
        // Header 
        $(el).find('thead').find('tr').each(function() { 
         excel += "<tr>"; 
         $(this).filter(':visible').find('th').each(function(index,data) { 
          if ($(this).css('display') != 'none'){     
           if(defaults.ignoreColumn.indexOf(index) == -1){ 
            excel += "<td>" + parseString($(this))+ "</td>"; 
           } 
          } 
         }); 
         excel += '</tr>';      

        });     


        // Row Vs Column 
        var rowCount=1; 
        $(el).find('tbody').find('tr').each(function() { 
         excel += "<tr>"; 
         var colCount=0; 
         $(this).filter(':visible').find('td').each(function(index,data) { 
          if ($(this).css('display') != 'none'){ 
           if(defaults.ignoreColumn.indexOf(index) == -1){ 
            excel += "<td>"+parseString($(this))+"</td>"; 
           } 
          } 
          colCount++; 
         });               
         rowCount++; 
         excel += '</tr>'; 
        });     
        excel += '</table>' 

        if(defaults.consoleLog == 'true'){ 
         console.log(excel); 
        } 

        var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:"+defaults.type+"' xmlns='http://www.w3.org/TR/REC-html40'>"; 
        excelFile += "<head>"; 
        excelFile += "<!--[if gte mso 9]>"; 
        excelFile += "<xml>"; 
        excelFile += "<x:ExcelWorkbook>"; 
        excelFile += "<x:ExcelWorksheets>"; 
        excelFile += "<x:ExcelWorksheet>"; 
        excelFile += "<x:Name>"; 
        excelFile += "{worksheet}"; 
        excelFile += "</x:Name>"; 
        excelFile += "<x:WorksheetOptions>"; 
        excelFile += "<x:DisplayGridlines/>"; 
        excelFile += "</x:WorksheetOptions>"; 
        excelFile += "</x:ExcelWorksheet>"; 
        excelFile += "</x:ExcelWorksheets>"; 
        excelFile += "</x:ExcelWorkbook>"; 
        excelFile += "</xml>"; 
        excelFile += "<![endif]-->"; 
        excelFile += "</head>"; 
        excelFile += "<body>"; 
        excelFile += excel; 
        excelFile += "</body>"; 
        excelFile += "</html>"; 

        var base64data = "base64," + $.base64.encode(excelFile); 
        window.open('data:application/vnd.ms-'+defaults.type+';filename=exportData.doc;' + base64data); 

       } 


       function parseString(data){ 

        if(defaults.htmlContent == 'true'){ 
         content_data = data.html().trim(); 
        }else{ 
         content_data = data.text().trim(); 
        } 

        if(defaults.escape == 'true'){ 
         content_data = escape(content_data); 
        } 



        return content_data; 
       } 

      } 
     }); 
    })(jQuery); 

Tutti gli altri file, inclusa la cartella jspdf possono essere eliminati.

In questo modo è possibile esportare la tabella in formato excel, doc e PowerPoint (in realtà, quando viene esportata in doc e powerpoint, ciò che si fa è incorporare un foglio di calcolo Excel nei documenti, quindi il plugin è lo stesso per tutti e tre formati)

utilizzare il plugin nello stesso modo come il plugin originale

+0

Ok, ci proverò e tornerò da te. –

Problemi correlati