Excel ve ODS dosyalarının Koşullu Biçimlendirmelerini ayarla
Giriş
Koşullu biçimlendirme, bir hücreye veya hücre aralığına biçim uygulamanıza ve bu biçimin hücrenin değeri veya bir formülin değeri ne olursa olsun değişmesine olanak tanıyan gelişmiş bir özelliktir. Örneğin, bir hücre değeri 500’den büyük olduğunda kalın görünmesini sağlayabilirsiniz. Hücrenin değeri koşulu karşıladığında, belirtilen biçim hücreye uygulanır. Hücrenin değeri koşulu karşılamıyorsa, hücrenin varsayılan biçimi kullanılır. Microsoft Excel’de, Biçim seçin, ardından Koşullu Biçimlendirme diyaloğunu açmak için tıklayın.
Aspose.Cells, hücrelere koşullu biçimlendirme uygulamayı destekler. Bu makale, bu konuyu açıklamaktadır. Ayrıca Excel’in renk ölçeği koşullu biçimlendirme için kullandığı rengi nasıl hesapladığını açıklar.
Koşullu Biçimlendirme Uygulama
Aspose.Cells, koşullu biçimlendirme uygulamayı birkaç şekilde destekler:
- Tasarımcı elek tablosu kullanarak
- Kopya yöntemi kullanarak.
- Çalışma zamanında koşullu biçimlendirme oluşturarak.
Tasarımcı Elek Tablosu Kullanma
Geliştiriciler, Microsoft Excel’de koşullu biçimlendirmeler içeren bir tasarımcı elektronik tablo oluşturabilir ve ardından o elektronik tabloyu Aspose.Cells ile açabilirler. Aspose.Cells, tasarımcı elektronik tabloyu yükler ve kaydeder, herhangi bir koşullu biçimlendirme ayarını korur.
Kopyalama Yöntemi Kullanımı
Aspose.Cells, geliştiricilere bir hücreden diğerine koşullu biçimlendirme ayarlarını çağırarak kopyalama imkanı sunar.
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Open a template Excel file | |
const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xlsx")); | |
// Get the first worksheet in the workbook | |
const sheet = workbook.getWorksheets().get(0); | |
// Get the A1 cell | |
const cell = sheet.getCells().get("A1"); | |
// Get the conditional formatting result object | |
const cfr = cell.getConditionalFormattingResult(); | |
// Get the icon set | |
const icon = cfr.getConditionalFormattingIcon(); | |
// Create the image file based on the icon's image data | |
require("fs").writeFileSync(path.join(dataDir, "imgIcon.out.jpg"), icon.getImageData()); |
Çalışma Zamanında Koşullu Biçimlendirme Uygulama
Aspose.Cells, çalışma zamanında koşullu biçimlendirme eklemeye ve kaldırmaya olanak tanır. Aşağıdaki kod örnekleri, koşullu biçimlendirme ayarlarını nasıl yapacağınızı gösterir:
- Bir çalışma kitabı örneği oluşturun.
- Boş bir koşullu biçimlendirme ekleyin.
- Biçimlendirmenin uygulanması gereken aralığı belirleyin.
- Biçimlendirme koşullarını tanımlayın.
- Dosyayı kaydedin.
Bu örneğin ardından, yazı tipi ayarları, kenarlık ayarları ve desen ayarları nasıl uygulanacağını gösteren birçok diğer küçük örnek gelir.
Microsoft Excel 2007, daha gelişmiş koşullu biçimlendirmeyi ekledi ve Aspose.Cells bunu da destekler. Buradaki örnekler, basit biçimlendirmeyi nasıl kullanacağınızı gösterirken, Microsoft Excel 2007 örnekleri daha gelişmiş koşullu biçimlendirme uygulamanın yollarını gösterir.
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
const filePath = path.join(dataDir, "Book1.xlsx"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
const sheet = workbook.getWorksheets().get(0); | |
// Adds an empty conditional formatting | |
const index = sheet.getConditionalFormattings().getCount(); | |
const fcs = sheet.getConditionalFormattings().get(index); | |
// Sets the conditional format range. | |
let ca = AsposeCells.CellArea.createCellArea(0, 0, 0, 0); | |
fcs.addArea(ca); | |
ca = AsposeCells.CellArea.createCellArea(1, 1, 1, 1); | |
fcs.addArea(ca); | |
// Adds condition. | |
const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "=A2", "100"); | |
// Adds condition. | |
const conditionIndex2 = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "50", "100"); | |
// Sets the background color. | |
const fc = fcs.get(conditionIndex); | |
fc.getStyle().setBackgroundColor(AsposeCells.Color.Red); | |
// Saving the Excel file | |
workbook.save(path.join(dataDir, "output.xls")); |
Yazı Tipi Ayarı
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Open a template Excel file | |
const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xlsx")); | |
// Get the first worksheet in the workbook | |
const sheet = workbook.getWorksheets().get(0); | |
// Get the A1 cell | |
const cell = sheet.getCells().get("A1"); | |
// Get the conditional formatting result object | |
const cfr = cell.getConditionalFormattingResult(); | |
// Get the icon set | |
const icon = cfr.getConditionalFormattingIcon(); | |
// Create the image file based on the icon's image data | |
require("fs").writeFileSync(path.join(dataDir, "imgIcon.out.jpg"), icon.getImageData()); |
Sınır Ayarı
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
const sheet = workbook.getWorksheets().get(0); | |
// Adds an empty conditional formatting | |
const index = sheet.getConditionalFormattings().add(); | |
const fcs = sheet.getConditionalFormattings().get(index); | |
// Sets the conditional format range. | |
const ca = AsposeCells.CellArea.createCellArea(0, 0, 5, 3); | |
fcs.addArea(ca); | |
// Adds condition. | |
const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "50", "100"); | |
// Sets the background color. | |
const fc = fcs.get(conditionIndex); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.LeftBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.RightBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.TopBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.BottomBorder).setLineStyle(AsposeCells.CellBorderType.Dashed); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.LeftBorder).setColor(new AsposeCells.Color(0, 255, 255)); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.RightBorder).setColor(new AsposeCells.Color(0, 255, 255)); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.TopBorder).setColor(new AsposeCells.Color(0, 255, 255)); | |
fc.getStyle().getBorders().get(AsposeCells.BorderType.BottomBorder).setColor(new AsposeCells.Color(255, 255, 0)); | |
workbook.save(path.join(dataDir, "output.xlsx")); |
Desen Ayarı
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Instantiating a Workbook object | |
const workbook = new AsposeCells.Workbook(); | |
const sheet = workbook.getWorksheets().get(0); | |
// Adds an empty conditional formatting | |
const index = sheet.getConditionalFormattings().add(); | |
const fcs = sheet.getConditionalFormattings().get(index); | |
// Sets the conditional format range. | |
const ca = AsposeCells.CellArea.createCellArea(0, 0, 5, 3); | |
fcs.addArea(ca); | |
// Adds condition. | |
const conditionIndex = fcs.addCondition(AsposeCells.FormatConditionType.CellValue, AsposeCells.OperatorType.Between, "50", "100"); | |
const fc = fcs.get(conditionIndex); | |
fc.getStyle().setPattern(AsposeCells.BackgroundType.ReverseDiagonalStripe); | |
fc.getStyle().setForegroundColor(new AsposeCells.Color(255, 255, 0)); | |
fc.getStyle().setBackgroundColor(new AsposeCells.Color(0, 255, 255)); | |
workbook.save(path.join(dataDir, "output.xlsx")); |
Gelişmiş Konular
- 2-Renkli Ölçek ve 3-Renkli Ölçek Koşullu Biçimlendirmeleri Ekle
- Çalışma Kitaplarında Koşullu Biçimlendirme Uygulamak
- Koşullu Biçimlendirme ile Sıfır Satır ve Sütunlara Gölgelendirme Uygulamak
- Koşullu Biçimlendirme Veri Çubukları Görüntüleri Oluşturmak
- Kullanılan Koşullu Biçimlendirme İkon Setleri, Veri Çubukları veya Renk Ölçekleri Nesnelerini Almak