AMPL to Excel ---- result

Hi, i’m trying to export the results of the schedules (assignment [c,r,d,t] =1) to excel, but i’m confused on how to do it.

load amplxl.dll;
table overall IN "amplxl" "timetable.xlsx" "overall":
    CODE <- [CODE], program, section, course_num, course_title, room, lec, lab, teaching_load, building;
table rooms IN "amplxl" "timetable.xlsx" "rooms":
    ROOMS <- [ROOMS], buildings, floor, type, lecture, laboratory;
    
read table overall;
read table rooms;

var assignment{CODE, ROOMS, DAYS, TIME} binary;
var room_assigned{CODE, ROOMS} binary;

i tried this code but it does not populate the excel

table result OUT "amplxl" "result.xlsx" "schedules":
   [CODE, ROOMS, DAYS, TIME] , assignment;  
write table result;

i also tried this code but get this error:

Abandoning compound command to accept declaration of result.
context:  [CODE, ROOMS, DAYS, TIME] ,  >>> assignment; <<<  
for {c in CODE, r in ROOMS, d in DAYS, t in TIME : assignment[c, r, d, t] = 1} {
	table result OUT "amplxl" "result.xlsx" "schedules":
		[CODE, ROOMS, DAYS, TIME] , assignment;             
}
write table result;

I ran a small test of your table and write table statements, and they worked for me — see the attached test code and Excel file. What was wrong when you tried to write assignment to the spreadsheet? The results should appear in the schedules tab.

You are getting the Abandoning compound command error because you have put a table statement inside a for loop. That would cause the table statement to be executed again in every pass through the loop, whereas you want to define the table only once. Instead, write a single table statement like this:

table result OUT "amplxl" "result.xlsx" "schedules":
   {c in CODE, r in ROOMS, d in DAYS, t in TIME: assignment[c,r,d,t] = 1}
      -> [CODE, ROOMS, DAYS, TIME], assignment;

test2.txt (489 Bytes)
result.xlsx (5.4 KB)