Cells の範囲のフォーマット
Contents
[
Hide
]
このトピックは、セルへのフォント設定およびその他の書式設定スタイルの適用に関連する一連のトピックにも属しています。前回のトピックでは、このような機能の処理について十分に説明しました。たとえば、次を参照できます。Cell のフォントと色を変更するとCells にスタイルを適用する同じ機能について学ぶためのトピック。次に、これらの概念について既に説明した場合、このトピックの新機能について説明します。このトピックと前のトピックの唯一の違いは、1 つのセルだけでなく、セルの範囲に (フォントやその他のスタイルに関連する) 書式設定を適用することです。このトピックが引き続き役立つことを願っています。
Cells の範囲のフォントとスタイルの設定
書式設定について話す前に (これまでのトピックですでに多くのことを話してきました)、セルの範囲を作成する方法について知っておく必要があります。さて、次を使用してセルの範囲を作成できますセル範囲セルの範囲を指定するためにいくつかのパラメーターを受け取るコンストラクターを持つクラス。を使用してセル範囲を指定できます名前また行と列のインデックス開始セルと終了セルの
作成したら、セル範囲オブジェクトのオーバーロードされたバージョンを使用できますスタイルの設定, SetFont & SetFontColorを取ることができる Worksheet のメソッドセル範囲オブジェクトを使用して、指定したセル範囲に書式設定を適用します。
この基本的な概念を理解するために例を見てみましょう。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Setting sample values | |
GridCell cell = sheet.Cells["b7"]; | |
cell.SetCellValue("1"); | |
cell = sheet.Cells["c7"]; | |
cell.SetCellValue("2"); | |
cell = sheet.Cells["d7"]; | |
cell.SetCellValue("3"); | |
cell = sheet.Cells["e7"]; | |
cell.SetCellValue("4"); | |
// Creating a CellRange object starting from "B7" to "E7" | |
CellRange range = new CellRange(6, 1, 6, 4); | |
// Accessing and setting Style attributes | |
Style style = new Style(this.gridDesktop1); | |
style.Color = Color.Yellow; | |
// Applying Style object on the range of cells | |
sheet.SetStyle(range, style); | |
// Creating a customized Font object | |
Font font = new Font("Courier New", 12f); | |
// Setting the font of range of cells to the customized Font object | |
sheet.SetFont(range, font); | |
// Setting the font color of range of cells to Red | |
sheet.SetFontColor(range, Color.Red); |