Data table concept in Aspose Java

Hi Team,


Could you explain the usage of Data table “ICellsDataTable” interface with an example, using WorkbookDesigner. And also could you please send the same source to my email including sample excel sheet what you are using.

Could you please post the answer asap, as i need it badly.

Thanks & Regards,
Bala Paluvari.

Hi Bala,

Thanks for your posting and considering Aspose.Cells.

Please see the implementation of ICellsDataTable interface and the example of its usage as below.

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();
}
}

Hi Team,

In relation to the above post there is a query regarding formatting of particular cell value while using CellDataTable and template based approach with smart markers. Issue here we are facing is unable to fetch single cell value from iteration of CellDataTable to format that cell with font styles etc.Could you please provide suggestions on the same which would be greatful for us. Thank you. Let me know if any detailed inputs are required.

Regards

Anitha

Hi Anitha,

Thanks for your posting and using Aspose.Cells.

Could you please explain your issue with more elaboration? Please provide us some sample code illustrating your issue. You could also provide us your actual output and expected output Excel files for reference. You can created your expected Excel file manually using Microsoft Excel and provide it to us. It will help us look into your issue precisely and we will be able to help you asap.