Formatting Smart Markers

Copy Style Attribute

Sometimes, when using smart markers, you want to copy the style of the cell that contains the smart marker tags. You can use the CopyStyle attribute of the smart marker’s tags for this purpose.

Copying Styles from Cells with Smart Markers

This example uses a simple template Microsoft Excel file with two markers in the A2 and B2 cells. The marker pasted in cell B2 uses the CopyStyle attribute, whereas the marker in cell A2 does not. Apply simple formatting (for example, set the font color to red and set the cell fill color to yellow).

This example uses a template file with a few markers in the cells.When executing the code, Aspose.Cells copies the formatting to all the records in column B but does not keep the formatting in column A.

public class CopyStyleData
{
private int year;
private String date;
public CopyStyleData(int year, String date)
{
this.year = year;
this.date = date;
}
public int getYear()
{
return year;
}
public void setYear(int year)
{
this.year = year;
}
public String getDate()
{
return date;
}
public void setDate(String date)
{
this.date = date;
}
}
List<CopyStyleData> dataList = new ArrayList<>();
dataList.add(new CopyStyleData(2010, "13/9/2010"));
dataList.add(new CopyStyleData(2010, "14/9/2010"));
dataList.add(new CopyStyleData(2009, "13/9/2009"));
dataList.add(new CopyStyleData(2009, "14/9/2009"));
dataList.add(new CopyStyleData(2009, "15/9/2009"));
dataList.add(new CopyStyleData(2010, "13/9/2010"));
dataList.add(new CopyStyleData(2010, "14/9/2010"));
dataList.add(new CopyStyleData(2010, "15/9/2010"));
dataList.add(new CopyStyleData(2009, "13/9/2009"));
dataList.add(new CopyStyleData(2009, "14/9/2009"));
// Instantiate the workbook from a template file that contains Smart Markers
Workbook book = new Workbook("template1.xlsx");
// Instantiate a new WorkbookDesigner
WorkbookDesigner designer = new WorkbookDesigner();
// Specify the workbook to the designer book
designer.setWorkbook(book);
// Set the data source
designer.setDataSource("DataList", dataList);
// Process the smart markers
designer.process(false);
// Save the Excel file
book.save("output_java.xlsx", SaveFormat.XLSX);

Adding Custom Labels

Introduction

While working with Smart Markers' grouping data feature, sometimes you need to add your own custom labels to the summary row. You also want to concatenate the Column’s name with that Label, e.g “Sub Total of Orders”. Aspose.Cells provides you Label and LabelPosition attributes, so you may place your custom labels in the Smart Markers while concatenating with the Subtotal rows in grouping data.

Adding custom Labels to concatenate with the Subtotal rows in Smart Markers

This example uses a template file with a few markers in the cells. When executing the code, Aspose.Cells adds some custom labels to the summary rows for the grouped data.

public class Report
{
private int year;
private String date;
private String assetClass;
private int reportedCost;
private int assessedValue;
public Report(int year, String date, String assetClass, int reportedCost, int assessedValue)
{
this.year = year;
this.date = date;
this.assetClass = assetClass;
this.reportedCost = reportedCost;
this.assessedValue = assessedValue;
}
public int getYear()
{
return year;
}
public void setYear(int year)
{
this.year = year;
}
public String getDate()
{
return date;
}
public void setDate(String date)
{
this.date = date;
}
public String getAssetClass()
{
return assetClass;
}
public void setAssetClass(String assetClass)
{
this.assetClass = assetClass;
}
public int getReportedCost()
{
return reportedCost;
}
public void setReportedCost(int reportedCost)
{
this.reportedCost = reportedCost;
}
public int getAssessedValue()
{
return assessedValue;
}
public void setAssessedValue(int assessedValue)
{
this.assessedValue = assessedValue;
}
}
List<Report> reportList = new ArrayList<>();
reportList.add(new Report(2010, "13/9/2010", "Fast Food Equipment", 400,160));
reportList.add(new Report(2010, "14/9/2010", "Fast Food Equipment", 800,1280));
reportList.add(new Report(2009, "13/9/2009", "Fast Food Equipment", 300, 90));
reportList.add(new Report(2009, "14/9/2009", "Fast Food Equipment", 600, 720));
reportList.add(new Report(2009, "15/9/2009", "Fast Food Equipment", 900, 2430));
reportList.add(new Report(2010, "13/9/2010", "Inventory", 100, 10));
reportList.add(new Report(2010, "14/9/2010", "Inventory", 200, 80));
reportList.add(new Report(2010, "15/9/2010", "Inventory", 300, 270));
reportList.add(new Report(2009, "13/9/2009", "Inventory", 200, 40));
reportList.add(new Report(2009, "14/9/2009", "Inventory", 400, 320));
// Instantiate the workbook from a template file that contains Smart Markers
Workbook book = new Workbook("template.xlsx");
// Instantiate a new WorkbookDesigner
WorkbookDesigner designer = new WorkbookDesigner();
// Specify the workbook to the designer book
designer.setWorkbook(book);
// Set the data source
designer.setDataSource("Report", reportList);
// Process the smart markers
designer.process();
// Save the Excel file
book.save("output_java.xlsx", SaveFormat.XLSX);