Hi,
Hi Mahesh,
Thanks for your posting and using Aspose.Cells for Java.
You can implement ICellsDataTable interface as shown below and then set your data source.
I have attached the sample xlsx file used in this code and output xlsx file generated by it for your reference.
Java
String filePath = “F:\Shak-Data-RW\Downloads\sample.xlsx”;
Workbook workbook = new Workbook(filePath);
WorkbookDesigner designer = new WorkbookDesigner(workbook);
CellsDataTableMap dataTable = new CellsDataTableMap();
designer.setDataSource(“dvCAdequacyHeaderAccts”, dataTable);
designer.process();
workbook.save(filePath + “.out.xlsx”);
----------------------------------
CellsDataTableMap.java
import com.aspose.cells.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/
* DataTable class (based on ASPOSE data table object)
* Has the member “mapList”. This will contain a list of elements parsed from the source XML file.
* The methods are called by the ASPOSE API when “designerobject.process” is executed.
* @author mattimob
*
*/
public class CellsDataTableMap implements ICellsDataTable {
private List mapList = new ArrayList();
private int index;
private String[] columns = new String[]{“Name”, “Age”};
/
* Constructor with the data type hashmap as parameter.
*
* @param elementMap
/
public CellsDataTableMap() {
/
* Create a ParseXML object (this is where the SAX Parser is) and pass the input XML file.
* The parser will parse the input XML, place the content in a Data object, add each Data
* object to a list and return this list to this caller.
*/
HashMap hm = new HashMap();
hm.put(“Name”, “Roberts”);
hm.put(“Age”, 33);
mapList.add(hm);
hm = new HashMap();
hm.put(“Name”, “James”);
hm.put(“Age”, 28);
mapList.add(hm);
index = -1;
}
public String[] getColumns() {
// String[] columns = new String[4];
// columns[0] = “startColumn”;
// columns[1] = “startRow”;
// columns[2] = “endColumn”;
// columns[3] = “endRow”;
return columns;
}
public int size() {
return this.mapList.size();
}
public void beforeFirst() {
index = -1;
}
public Object get(int columnIndex) {
if(index < 0 || index >= this.size()) {
return false;
}
if(columnIndex > columns.length)
{
return null;
}
return get(columns[columnIndex]);
}
public boolean next() {
index += 1;
if(index >= this.mapList.size()) {
return false;
}
return true;
}
/**
* Returns the value of the designated column in the current row.
*
* @param columnName
* the property name of the POJO.
* @return the value of the designated column in the current row.
*/
public Object get(String columnName) {
HashMap dataMap = (HashMap) this.mapList.get(index);
return dataMap.get(columnName);
}
public int getCount() {
// TODO Auto-generated method stub
return this.mapList.size();
}
}