Форматирование Smart Markers
Копирование атрибута стиля
Иногда, при использовании умных маркеров, вы хотите скопировать стиль ячейки, содержащей теги умных маркеров. Вы можете использовать атрибут CopyStyle тегов умных маркеров для этой цели.
Копирование стилей из ячеек с умными маркерами
В этом примере используется простой шаблонный файл 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); |