Using IronPython to export markedd data to Excel file results in an empty file

I am trying to write an IronPython code that exports the marked items from a MapChart (i.e. select a few data points from the map) to an Excel (xls) file. The code below downloads the file onto the desired location but it is empty (i.e. only the headers are stored in the excel file

That is the current code I have:

from System.IO import File
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers

writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsDataWriter)
table = Document.Data.Tables['WellsData']
filtered = Document.ActiveFilteringSelectionReference.GetSelection(table).AsIndexSet()
stream = File.OpenWrite("C:\Users\user\Desktop\dropdownexport.xls")
names =[]
for col in table.Columns:
writer.Write(stream, table, filtered, names)


(1) Answer