格式化 Smart Markers

复制样式属性

有时,使用 Smart Markers 时,您希望复制包含 Smart Marker 标记的单元格的样式。您可以使用 Smart Markers 标记的 CopyStyle 属性来实现此目的。

从包含 Smart Markers 的单元格复制样式

此示例使用一个简单的模板 Microsoft Excel 文件,其中包含两个 A2 和 B2 单元格中的标记。粘贴在 B2 单元格中的标记使用 CopyStyle 属性,而 A2 单元格中的标记则不使用。应用简单的格式(例如,将字体颜色设置为 红色,单元格填充颜色设置为 黄色)。

此示例使用 模板文件,其中在单元格中有几个标记。当执行代码时,Aspose.Cells 将格式复制到 B 列中的所有记录,但不保留 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);

添加自定义标签

介绍

在使用 Smart Markers 的分组数据功能时,有时您需要向汇总行添加自定义标签。您还希望将列的名称与该标签连接起来,例如 “订单的小计”。Aspose.Cells 为您提供了 Label 和 LabelPosition 属性,因此您可以将自定义标签放置在 Smart Markers 中,并在分组数据中将其与小计行连接起来。

将自定义标签添加到智能标记中以与小计行连接

此示例使用一个包含少量标记的模板文件。执行代码时,Aspose.Cells会为分组数据的汇总行添加一些自定义标签。

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