Error exporting selected table lines to Excel

I have an fpmi table that the users select rows from and export them to Excel. I sometimes get an error, which I think may be because some of the fields are null and I can’t seem to get this to work.

Here is what I have:

table = event.source.parent.getComponent("Table")
rows = table.getSelectedRows()
headers = ["ID","Code","DtFilled","Gen","FermTank","DtReck","pH","CellCt","Trub","Viability"]
data = []
line = []
pdata = fpmi.db.toPyDataSet(
for row in rows:
	for col in range(
	line = []
exportds = fpmi.db.toDataSet(headers,data)

There are actually 18 columns in the dataset, I just shorted the header listing in the code here.
The error I get varies as to line and column reporting the error depending on what rows I selected.

ERROR - Error executing script for event: mouseClicked
on component: Table. [AWT-EventQueue-0]
Traceback (innermost last):
File “event:mouseClicked”, line 13, in ?
TypeError: Unable to convert row 4, column 5 to type class java.lang.String

at org.python.core.Py.TypeError(
at com.inductiveautomation.factorypmi.application.script.builtin.DatasetUtilities.toDataSet(
at com.inductiveautomation.factorypmi.application.script.builtin.DBUtilities.toDataSet(
at sun.reflect.GeneratedMethodAccessor584.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(
at org.python.core.PyReflectedFunction.__call__(
at org.python.core.PyObject.__call__(
at org.python.core.PyObject.invoke(
at org.python.pycode._pyx108.f$0(<event:mouseClicked>:13)
at org.python.pycode._pyx108.call_function(<event:mouseClicked>)
at org.python.core.Py.runCode(
at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(
at $Proxy1.mouseClicked(Unknown Source)
at com.inductiveautomation.factorypmi.application.components.util.EventDelegateDispatcher$MouseEventDispatcher.mouseClicked(

Yes, I think you’re right - null values are throwing it off.
fpmi.dataset.toDataSet() uses the types of the values in the first row to intuit the column types. If any values in the first row are null, it guesses the type, but clearly it is guessing wrong.

I think that this could be improved so that column types are defined by the first non-null value encountered in each column. I’ve put this in for 3.3.1.

The workaround would be to “seed” the data list with a fake row with all non-null values of the proper type, and then pop that first row off before you convert data into pdata.

Uh, scratch that. That clearly won’t work. Sorry, wasn’t thinking straight.

Thanks anyway for the attempt. I should mention that this is not something I have to impliment this week as the user can export the entire table and take just what they want from the spreadsheet itself, so I can wait for the release of 3.3.1.