Questions about using flexscript to import excel

j08j
Not applicable
1 View
6 Replies
Message 1 of 7

Questions about using flexscript to import excel

j08j
Not applicable

[ FlexSim 24.0.2 ]

I want to use flexscript to import the Data.xlsx file into GlobalTable1 according to the settings in the figure below, but it has not been successful.

截圖-2024-06-11-上午11159.png截圖-2024-06-11-上午11244.png

Where is the problem?

Thanks for the help.

0 Likes
Accepted solutions (1)
2 Views
6 Replies
Replies (6)
Message 2 of 7

moehlmann_fe
New Member
New Member
Accepted solution

In the command "excelimporttable()" you have to actually specify the start row/column and number of rows/columns to import. The target table also must already have these dimensions as it will not automaically resize to fit the data and the data types of its columns must also match the data in the excel file.

You can also run the import defined in the interface with "excelmultitableimport()".

0 Likes
Message 3 of 7

j08j
Not applicable

There are my excel sheets:截圖-2024-06-11-下午44510.png

截圖-2024-06-11-下午44520.pngI made the following modifications:截圖-2024-06-11-下午44618.png

but it shows error:截圖-2024-06-11-下午45159.png

0 Likes
Message 4 of 7

moehlmann_fe
New Member
New Member
Are you trying to read a value from the tables after importing? Because you are not setting their size. Newly created tables will have one row and one column. As I mentioned already, the excelimporttable() command will not adjust their size by itself. Use "Table().setSize()" before you import.
0 Likes
Message 5 of 7

j08j
Not applicable

Thanks, it works successfully. But I have a question. If the data in Sheet1 is a different array size every time I inport it, what should I do? Is there any other way besides directly setting a super large size?

0 Likes
Message 6 of 7

moehlmann_fe
New Member
New Member
As mentioned in the answer, you can define the import parameters in the Excel interface and then run that through code (so the range of values and table resizing happen automatically).

Or you read the excel file row by row (excelreadnum(), excelreadstr(), excelreadcell()) as long as there is valid data and add a new row to the table every time.

0 Likes
Message 7 of 7

j08j
Not applicable

I'll give it a try, thanks for your help!

0 Likes