question

Pierre G avatar image
0 Likes"
Pierre G asked Joerg Vogel commented

How to check if an Excel Workbook is already opened ?

Hi,


When I do an export (with the Excel Interface or by code with excelmultitableexport()), I need to manually close the destination Excel Workbook before the export. If I don't do it, the export will seem to work (no error message and I can see the export progress bar) but the data won't be "exported" (or maybe they are instantly "crushed" when I close and re-open the Excel workbook to watch my data).

I imagine that FlexSim won't be able to close the Excel Workbook. But is there a way to check if the destination Excel Workbook is already opened before to start my export (with excelmultitableexport()) ? I want to warn the user and ask him to manually close the Excel Woorkbook if it's already open.


I tried to use excelopen(), excelclose(), ... but it doesn't seem to work. Or maybe I'm not using it the right way.

I'm using Office 365, Excel version 2302, build 16130.20218.


Thanks for your help.

FlexSim 23.0.4
excelexcel exportexcelcloseexcelopen
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Kavika F avatar image
0 Likes"
Kavika F answered Kavika F commented

Hey @Pierre G, there's no built-in FlexSim way to check if an Excel program is open (that I know of). However, you can make a simple Python function that prompts you to close every Excel file that's open.

  1. # closeExcels.py
  2. import subprocess
  3.  
  4. def promptCloseExcels():
  5. subprocess.call(["taskkill", "/T","/IM",EXCEL_PROCESS])

In FlexSim, you can make a User Command that calls this script. Then you can run this script before you try to export to your tables.

1678902136369.png

(If you need help hooking up a Python Script, you can check out this post for guidance).

I'll attach the files I used so you can play around with it.

test-export.fsm

Testing.xlsx

closeExcels.py


1678902136369.png (38.5 KiB)
test-export.fsm (68.1 KiB)
testing.xlsx (8.1 KiB)
closeexcels.py (374 B)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.