How to add and modify a table with Xml data source

How can I add, or modify an existing, table that gets its data from XML?
I would like to add columns and specify the xpath where the data should be retrieved from.

To configure a single cell to retrieve its data from the XML I can use sheet.getCells().linkToXmlMap(“shiporder_Map”, 0, 0, “/shiporder/shipto/name”);

On an existing table I can query the data source type with
sheet.getListObjects().get(0).getDataSourceType();
but I have not found a way to set the data source.

Regards
Rickard Eklind

@eklind,

Thanks for the details.

I guess the feature is not supported as I too could not find the relevant APIs. I have logged a ticket for your requested feature/issue as following:
CELLSJAVA-42617 - Add and modify a Table/ListObject with Xml data source

We will check if we could support it or there is some other way around to implement your needs. Once we have an update on it, we will let you know here.

@eklind,

Please find attached the file “Book1.xlsx” which has an xml map named “catalog_Map” and two tables in the cell areas, i.e., “H4:I5” and “Q4:S5”. You can link to a cell besides an existing table column head, it will auto merge, like adding a column to the table. Also you can link to an existing table column head which does not link to map. See the sample code with attached file for your reference:
e.g
Sample code:

Workbook wb = new Workbook("Book1.xlsx");
        Cells cells = wb.getWorksheets().get(0).getCells();
        
        //Link to a cell besides an existing table column head, it will auto merge. Like adding a column to the table.
        cells.linkToXmlMap("catalog_Map", 3, 9, "/catalog/book/author");
        
        //Link to an existing table column head which does not link to map.
        cells.linkToXmlMap("catalog_Map", 3, 16, "/catalog/book/price");

    wb.save(outFile.xlsx); 

Hope, this helps a bit and let us know if it suits your needs.
file1.zip (7.7 KB)