Koşullu Biçimlendirme ile Sıradaki Satır ve Sütunlara Gölge Uygula

Contents
[ ]

Bu makale, Excel’in yerleşik işlevleri ROW, COLUMN ve MOD’u kullanmaktadır. İleride sunulan kod örneğini daha iyi anlayabilmek için bu işlevlerin bazı ayrıntıları aşağıda verilmiştir.

  • ROW() fonksiyonu, bir hücre referansının satır numarasını döner. Referans parametresi belirtilmediyse, fonksiyonun girildiği hücrenin adresi referans alınır.
  • COLUMN() fonksiyonu, bir hücre referansının sütun numarasını döner. Referans parametresi belirtilmediyse, fonksiyonun girildiği hücrenin adresi referans alınır.
  • MOD() işlevi, bir sayının bir bölen tarafından bölündükten sonra kalanı döndürür. İşlevin ilk parametresi, kalanını bulmak istediğiniz sayısal değeri, ikinci parametre ise bu sayısal değeri bölmek için kullanılan parametreyi temsil eder. Bölen 0 ise, #DIV/0! hatası döndürür.

Bu hedefe ulaşmak için bazı kodlar yazmaya başlayalım ve Aspose.Cells for Node.js via C++ API’sinden yardım alalım.

const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create an instance of Workbook or load existing
const book = new AsposeCells.Workbook();
// Access the Worksheet on which desired rule has to be applied
const sheet = book.getWorksheets().get(0);
// Add FormatConditions to the instance of Worksheet
let idx = sheet.getConditionalFormattings().add();
// Access the newly added FormatConditions via its index
const conditionCollection = sheet.getConditionalFormattings().get(idx);
// Define a CellsArea on which conditional formatting will be applicable
// The code creates a CellArea ranging from A1 to I20
const area = AsposeCells.CellArea.createCellArea("A1", "I20");
// Add area to the instance of FormatConditions
conditionCollection.addArea(area);
// Add a condition to the instance of FormatConditions
// For this case, the condition type is expression, which is based on some formula
idx = conditionCollection.addCondition(AsposeCells.FormatConditionType.Expression);
// Access the newly added FormatCondition via its index
const formatCondition = conditionCollection.get(idx);
// Set the formula for the FormatCondition
formatCondition.setFormula1("=MOD(ROW(),2)=0");
// Set the background color and pattern for the FormatCondition's Style
formatCondition.getStyle().setBackgroundColor(AsposeCells.Color.Blue);
formatCondition.getStyle().setPattern(AsposeCells.BackgroundType.Solid);
// Save the result on disk
book.save(path.join(dataDir, "output_out.xlsx"));

Aşağıdaki görüntü, Excel uygulamasında yüklenen sonuç elektronik tabloyu göstermektedir.

todo:image_alt_text

Sıralı sütunlara gölge uygulamak için yapmanız gereken tek şey, =MOD(ROW(),2)=0 formülünü =MOD(COLUMN(),2)=0 olarak değiştirmektir; yani, satır dizinini almak yerine formülü sütun dizinine değiştirin.
Bu durumda elde edilen elektronik tablo aşağıdaki gibi görünecektir.

todo:image_alt_text