Error opening exported excel file in PHP

Asked

Viewed 255 times

2

I use the following code:

<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br" xml:lang="pt-br">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <link rel="stylesheet" href="bootstrap/style.css">
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="bootstrap/css/datatables.css">
    <script src="bootstrap/js/jquery.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <script src="bootstrap/js/jquery.dataTables.min.js"></script>
    <script src="bootstrap/js/datatables.js"></script>
    <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />
<style type="text/css">

.button_example{
border:1px solid #616261;-webkit-box-shadow: #b4b5b5 7px 7px 7px  ;-moz-box-shadow: #b4b5b5 7px 7px 7px ; box-shadow: #b4b5b5 7px 7px 7px  ; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;font-family:arial, helvetica, sans-serif; padding: 10px 10px 10px 10px; text-decoration:none; display:inline-block;text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #FFFFFF;
 background-color: #7d7e7d; background-image: -webkit-gradient(linear, left top, left bottom, from(#7d7e7d), to(#080A0D));
 background-image: -webkit-linear-gradient(top, #7d7e7d, #080A0D);
 background-image: -moz-linear-gradient(top, #7d7e7d, #080A0D);
 background-image: -ms-linear-gradient(top, #7d7e7d, #080A0D);
 background-image: -o-linear-gradient(top, #7d7e7d, #080A0D);
 background-image: linear-gradient(to bottom, #7d7e7d, #080A0D);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#7d7e7d, endColorstr=#080A0D);
}

.button_example:hover{
 border:1px solid #4a4b4a;
 background-color: #646464; background-image: -webkit-gradient(linear, left top, left bottom, from(#646464), to(#1b222d));
 background-image: -webkit-linear-gradient(top, #646464, #1b222d);
 background-image: -moz-linear-gradient(top, #646464, #1b222d);
 background-image: -ms-linear-gradient(top, #646464, #1b222d);
 background-image: -o-linear-gradient(top, #646464, #1b222d);
 background-image: linear-gradient(to bottom, #646464, #1b222d);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#646464, endColorstr=#1b222d);
}
</style>
    </head>
<body>
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="reposicao.php"></a>
      <img src="img/logo.png" height="50" width="100">
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
      </ul>

      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">LOJA:&nbsp;&nbsp;<?php echo"00$v_loja ";?></a></li>
        <li><a href="#">USUARIO:&nbsp;&nbsp;<?php echo"$v_nome $v_sobrenome ";?></a></li>&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;<li><a href="logout.php"><span class="glyphicon glyphicon-off">&nbsp;SAIR</span></a></li>
      </ul>
    </div>
  </div>
</nav>
    <div class="container">
      <div class="row">
        <div class="col-md-12">
            <a class="button_example" href="menu_principal.php"><span class="glyphicon glyphicon-arrow-left"></span>&nbsp;VOLTAR</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a class="button_example" id="exportButton"><span class="fa fa-file-excel-o"></span>&nbsp;EXPORTAR</a>
      <?php
      $query_frase = mysql_query("SELECT 
     frase_id   AS ID, 
     frase_desc AS DESCRICAO
       FROM frases_sistema ");
        while ($row = mysql_fetch_array($query_frase)) {
        $v_frase    = $row["DESCRICAO"];
           }


        ?>

    <div align="left"><h4><?php echo"$v_frase";?></h4></div><div align="right"><div class="panel-title">
      <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><center><b><?php echo"$v_descricao_categoria"; ?></center></h3></b>
      </div>
      <div class="panel-body">
      <link rel="stylesheet" type="text/css" href="/Content/font-awesome/css/font-awesome.min.css" />
    <table id="exportTable" class='datatable table table-hover table-bordered table-responsiv' align='center'>
       <thead>
         <tr>
            <th align='center'><font size=2>ITEM</font></th>
            <th align='center'><font size=2>DESCRICAO</font></th>
            <th align='center'><font size=2>DIAS_DE_GIRO</font></th>
            <th align='center'><font size=2>FATOR</font></th>
            <th align='center'><font size=2>ESTOQUE</font></th>
            <th align='center' bgcolor='#D0D0D0'><font size=2>NECESSIDADE</font></th>
            <th align='center' bgcolor='#FFFF66'><font size=2>PEDIDO</font></th>
            <th align='center' bgcolor='#FFFF66'><font size=2>BANCAO</font></th>
            <th align='center' bgcolor='#FFFF66'><font size=2>ROMANEIO</font></th>
            <th align='center' bgcolor='#FFFF66'><font size=2>TRANSITO</font></th>
            <th align='center' bgcolor='#FFCC00'><font size=2>GONDOLA</font></th>
            <th align='center' bgcolor='#00CC00'><font size=2>REPOSICAO</font></th>
         </tr>
        </thead>
      <?php
         echo"<tbody>";   
         while ($row = mysql_fetch_array($sql_retorno)) {
         echo" <tr>";
            echo"<td align='center'><font size=2> ".$row['ITEM'].                             "</font></td>";
            echo"<td><font size=2>".$row['DESCRICAO'].                        "</font></td>";
            echo"<td align='center'><font size=2><b>".$row['DIAS_DE_GIRO'].                  "</font></b></td>";
            echo"<td align='center'><font size=2><b>".$row['FATOR'].                         "</font></b></td>";
            echo"<td align='center'><font size=2><b>".$row['ESTOQUE'].                       "</font></b></td>";
            echo"<td align='center' bgcolor='#D0D0D0'><font size=2><b>".$row['NECESSIDADE']. "</font></b></td>";
            echo"<td align='center' bgcolor='#FFFF66'><font size=2><b>".$row['PEDIDO'].      "</font></b></td>";
            echo"<td align='center' bgcolor='#FFFF66'><font size=2><b>".$row['BANCAO'].      "</font></b></td>";
            echo"<td align='center' bgcolor='#FFFF66'><font size=2><b>".$row['ROMANEIO'].    "</font></b></td>";
            echo"<td align='center' bgcolor='#FFFF66'><font size=2><b>".$row['TRANSITO'].    "</font></b></td>";
            echo"<td align='center' bgcolor='#FFCC00'><font size=2><b>".$row['GONDOLA'].     "</font></b></td>";
            echo"<td align='center' bgcolor='#00CC00'><font size=2><b>".$row['REPOSICAO'].   "</font></b></td>";
         echo" </tr>";
            }   
      echo"  </tbody>";
     echo" </table>";

    ?>
        </div>
       </div>
      </div>
     </div>
    </div>
    <!-- you need to include the shieldui css and js assets in order for the components to work -->
    <link rel="stylesheet" type="text/css" href="http://www.shieldui.com/shared/components/latest/css/light/all.min.css" />
    <script type="text/javascript" src="http://www.shieldui.com/shared/components/latest/js/shieldui-all.min.js"></script>
    <script type="text/javascript" src="http://www.shieldui.com/shared/components/latest/js/jszip.min.js"></script>

    <script type="text/javascript">
        jQuery(function ($) {
            $("#exportButton").click(function () {
                // parse the HTML table element having an id=exportTable
                var dataSource = shield.DataSource.create({
                    data: "#exportTable",
                    schema: {
                        type: "table",
                        fields: {
                            ITEM:         { type: Number },
                            DESCRICAO:    { type: String },
                            DIAS_DE_GIRO: { type: Number },
                            FATOR:        { type: Number },
                            ESTOQUE:      { type: Number },
                            NECESSIDADE:  { type: Number },
                            PEDIDO:       { type: Number },
                            BANCAO:       { type: Number },
                            ROMANEIO:     { type: Number },
                            TRANSITO:     { type: Number },
                            GONDOLA:      { type: Number },
                            REPOSICAO:    { type: Number }
                        }
                    }
                });

                // when parsing is done, export the data to Excel
                dataSource.read().then(function (data) {
                    new shield.exp.OOXMLWorkbook({
                        author: "REPOSIÇÃO",
                        worksheets: [
                            {
                                name: "relatorio",
                                rows: [
                                    {
                                        cells: [
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "ITEM"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: String,
                                                value: "DESCRICAO"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "DIAS_DE_GIRO"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "FATOR"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "ESTOQUE"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "NECESSIDADE"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "PEDIDO"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "BANCAO"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "ROMANEIO"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "TRANSITO"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "GONDOLA"
                                            },
                                            {
                                                style: {
                                                    bold: true
                                                },
                                                type: Number,
                                                value: "REPOSICAO"
                                            }
                                        ]
                                    }
                                ].concat($.map(data, function(item) {
                                    return {
                                        cells: [
                                            { type: Number, value: item.ITEM},
                                            { type: String, value: item.DESCRICAO},
                                            { type: Number, value: item.DIAS_DE_GIRO},
                                            { type: Number, value: item.FATOR},
                                            { type: Number, value: item.ESTOQUE},
                                            { type: Number, value: item.NECESSIDADE},
                                            { type: Number, value: item.PEDIDO},
                                            { type: Number, value: item.BANCAO},
                                            { type: Number, value: item.ROMANEIO},
                                            { type: Number, value: item.TRANSITO},
                                            { type: Number, value: item.GONDOLA},
                                            { type: Number, value: item.REPOSICAO}
                                        ]
                                    };
                                }))
                            }
                        ]
                    }).saveAs({
                        fileName: "reposicao"
                    });
                });
            });
        });
    </script>
      </body>
    </html>

Exports perfectly, but when opening gives these 2 messages:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

If I give yes and then close opens normally, but would like to remove these messages.

Does anyone know what it can be?

  • I wanted to understand these tags there.

  • This is for safety. You would like Excel to execute any code from a file you just downloaded from the Internet?

1 answer

1


Otácio, see this link:

Autorun macros in Excel

In your case, as Excel is running and so gives these messages, see if it is possible to resolve by autorunning a macro "before" your reading process is loaded.

Otherwise, if Excel will run anyway, you could try to create a suitable reading macro for your case. I know it’s not ideal because of your question.

See if the first tip solves, good luck!

  • Just one observation: Setting up Excel to run code automatically can lead to severe security breaches. This is not recommended on virtually any occasion, especially when speaking on a desktop, as it may allow third parties to capture and monitor computer data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.