I'm trying to incorporate Apache MetaModel into a project and keep running into a weird problem. I update an Excel spreadsheet row in code. The code finds the right row, deletes it, then appends the row (with my update) to the bottom of the spreadsheet. I'd like the update to happen in-place, with the same data staying in the same row. I thought it was something I was doing wrong, then set up a stupid simple project to duplicate the behavior. Unfortunately, the problem remains.
Here's the xlsx file:
Name Address City State Zip
Bob 123 Main St. Norman OK 11111
Fred 989 Elm Street Chicago IL 22222
Mary 555 First Street San Francisco CA 33333
Now, I want to update Bob's Zip to "None".
package MMTest;
import java.io.File;
import org.apache.metamodel.UpdateableDataContext;
import org.apache.metamodel.excel.ExcelDataContext;
import org.apache.metamodel.schema.Column;
import org.apache.metamodel.schema.Schema;
import org.apache.metamodel.schema.Table;
import org.apache.metamodel.update.Update;
public class MMTest {
public static void main(String[] args) {
UpdateableDataContext excel = new ExcelDataContext(new File("C:/test/test.xlsx"));
Schema schema = excel.getDefaultSchema();
Table[] tables = schema.getTables();
assert tables.length == 1;
Table table = schema.getTables()[0];
Column Name = table.getColumnByName("Name");
Column Zip = table.getColumnByName("Zip");
excel.executeUpdate(new Update(table).where(Name).eq("Bob").value(Zip, "None"));
}
}
Pretty simple right? Nope. This is the result:
Name Address City State Zip
<blank line>
Fred 989 Elm Street Chicago IL 22222
Mary 555 First Street San Francisco CA 33333
Bob 123 Main St. Norman OK None
Am I missing something simple? The documentation is pretty sparse, but I've read everything the internet has to offer on this package. I appreciate your time.