如何检查Excel电子表格是否正在运行,在if命令中使用它并运行工作表(如果它尚未运行)

时间:2017-03-03 15:54:41

标签: batch-file

我一直试图用批量设置一些东西。我一直试图建立的东西是打开一个excel电子表格,其中包含我编写的一些我需要完成的功课。虽然,当我试图检查电子表格是否打开时,我遇到了一个小问题。我试着看一些解决我问题的方法,但我从来没有真正理解如何使用它们或者它们不是为xlxs制作的。我目前拥有的是这段代码:

<?php
foreach ($sections as $section)
{
   $insc = Inscripciones::getAllInscriptionBySection($section -> getId());
   if (count($insc) > 0)
   {
     ?>
     <h2 style="margin-bottom: 50px;"><?php echo $section->getNombre(); ?></h2>
     <table class="table table-bordered table-striped mb-none" id="datatable-tabletools-<?php echo $section -> getId(); ?>">
       <thead>
         <tr>
           <th style="width: 60px; text-align: center;">Id</th>
           <th style="width: 450px; text-align: center;">Category</th>
           <th style="width: 390px; text-align: center;">Title</th>
           <th style="width: 140; text-align: center;">Usuario</th>
           <th style="width: 100px; text-align: center;">Acciones</th>
         </tr>
       </thead>
       <tbody>
         <!-- tbody also dynamically populated -->
       </tbody>
     </table>
  <?php
  }
}
  ?>



    <script type="text/javascript">
          $(document).ready(function () {
           $('#datatable-tabletools-1').DataTable({
           });
           $('#datatable-tabletools-2').DataTable({
           })
           $('#datatable-tabletools-3').DataTable({
           })
          });
   </script>

1 个答案:

答案 0 :(得分:3)

问题是你的代码像fork炸弹一样循环,我猜你试图通过验证Excel的实例是否正在运行来阻止循环。

tasklist /FI "IMAGENAME eq EXCEL.EXE" 2>NUL | find /I /N "EXCEL.EXE">NUL
if "%ERRORLEVEL%"=="0" //commands here

它将检查是否有任何excel文件在预览窗格中打开,运行甚至预览。