Formateo de marcadores inteligentes
Atributo de estilo de copia
A veces, al usar marcadores inteligentes, desea copiar el estilo de la celda que contiene las etiquetas de marcador inteligente. Puede utilizar el atributo CopyStyle de las etiquetas de marcador inteligente para este propósito.
Copia de estilos de celdas con marcadores inteligentes
Este ejemplo utiliza un archivo de plantilla de Microsoft Excel simple con dos marcadores en las celdas A2 y B2. El marcador pegado en la celda B2 utiliza el atributo CopyStyle, mientras que el marcador en la celda A2 no lo hace. Aplique un formato simple (por ejemplo, configure el color de la fuente a rojo y configure el color de relleno de la celda a amarillo).
Este ejemplo utiliza un archivo de plantilla con algunos marcadores en las celdas. Al ejecutar el código, Aspose.Cells copia el formato a todos los registros en la columna B pero no conserva el formato en la columna 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); |
Agregar etiquetas personalizadas
Introducción
Mientras se trabaja con la función de agrupación de datos de Smart Markers, a veces es necesario agregar sus propias etiquetas personalizadas a la fila de resumen. También se quiere concatenar el nombre de la columna con esa etiqueta, por ejemplo “Subtotal de Pedidos”. Aspose.Cells le proporciona los atributos Label y LabelPosition, para que pueda colocar sus etiquetas personalizadas en los Smart Markers mientras se concatenan con las filas de subtotal en la agrupación de datos.
Agregar etiquetas personalizadas para concatenar con las filas de subtotal en Smart Markers
Este ejemplo utiliza un archivo de plantilla con algunos marcadores en las celdas. Al ejecutar el código, Aspose.Cells agrega algunas etiquetas personalizadas a las filas de resumen para los datos agrupados.
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); |