スタイルオブジェクトの再利用

Contents
[ ]

ワークシート内の大きな範囲のセルにフォーマットを適用するには:

  1. スタイルオブジェクトを作成します。
  2. 属性を指定します。
  3. 範囲のセルにスタイルを適用します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ReuseStyleObjects.class);
// Create an instance of Workbook & load an existing spreadsheet
Workbook workbook = new Workbook(dataDir + "Book1.xls");
// Retrieve the Cell Collection of the first Worksheet
Cells cells = workbook.getWorksheets().get(0).getCells();
// Create an instance of Style and add it to the pool of styles
Style styleObject = workbook.createStyle();
// Retrieve the Font object of newly created style
Font font = styleObject.getFont();
// Set the font color to Red
font.setColor(Color.getRed());
// Set the newly created style on two different cells
cells.get("A1").setStyle(styleObject);
cells.get("A2").setStyle(styleObject);

上記で説明したプロセスと同様に実行できます。

cells.get("A1").getStyle().getFont().setColor(Color.getRed());
cells.get("A2").getStyle().getFont().setColor(Color.getRed());