Updating excel file with apache metamodel

I am trying to include Apache MetaModel in a project and get confused about a strange problem. I am updating an Excel table row in code. The code finds the right row, deletes it, and then adds the row (with my update) to the bottom of the table. I want the update to happen in place, with the same data remaining on the same line. I thought this was what I was doing wrong, and then created a stupid simple project to duplicate behavior. Unfortunately, the problem remains.

Here is 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 upgrade Bob 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? 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 rare, but I read everything the internet has to offer on this package. I appreciate your time.

+4
2

, . ExcelDeleteBuilder.java

,

    for (Row row : rowsToDelete) {
        sheet.removeRow(row);
    }

    for (Row row : rowsToDelete) {
        int rowNum = row.getRowNum() + 1;
        sheet.removeRow(row);
        sheet.shiftRows(rowNum, sheet.getLastRowNum(), -1);
    }

. POI Apache shiftRows(). , "" , , .

N.B. Apache Metamodel 4.5.4

+1

. ExcelDataContext . - apache. UpdateCallback DeleteAndInsertCallback, , . , , ( , ExcelDataContext). https://issues.apache.org/jira/browse/METAMODEL . unit test https://git-wip-us.apache.org/repos/asf/metamodel.git

0

All Articles