SmartMarkersのフォーマット設定
スタイル属性のコピー
スマートマーカーtagsを持つセルのスタイルをコピーする場合には、そのためにスマートマーカーtagsのCopyStyle属性を使用することができます。
スマートマーカーを含むセルからスタイルをコピーするための簡単な例です。この例では、A2およびB2のセルに2つのマーカーが使用されています。セルB2に貼り付けられたマーカーはCopyStyle属性を使用していますが、セルA2のマーカーは使用していません。簡単な書式設定(たとえばフォントの色を赤に設定し、セルの塗りつぶし色をイエローに設定します)。
この例では、A2およびB2のセルに2つのマーカーを持つシンプルなテンプレートMicrosoft Excelファイルが使用されています。セル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 はラベルと LabelPosition 属性を提供しているため、グループ化データの Smart Markers にカスタムラベルを配置し、サマリー行と連結することができます。
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); |