Генерация изображений полос данных условного форматирования
Contents
[
Hide
]
Иногда вам может потребоваться создать изображения условного форматирования панелей данных. Вы можете использовать метод Aspose.Cells DataBar.toImage(Cell, ImageOrPrintOptions) для создания этих изображений. В этой статье показано, как создать изображение панели данных с помощью Aspose.Cells.
Следующий пример кода создает изображение DataBar для ячейки C1. Он сначала обращается к объекту условного форматирования ячейки, затем через этот объект — к DataBar объекту и использует его метод DataBar.toImage(Cell, ImageOrPrintOptions) для генерации изображения ячейки. В конце он сохраняет изображение на диск.
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
const path = require("path"); | |
const fs = require("fs"); | |
const AsposeCells = require("aspose.cells.node"); | |
// Source directory | |
const sourceDir = RunExamples.Get_SourceDirectory(); | |
// Output directory | |
const outputDir = RunExamples.Get_OutputDirectory(); | |
// Create workbook object from source excel file | |
const workbook = new AsposeCells.Workbook(path.join(sourceDir, "sampleGenerateDatabarImage.xlsx")); | |
// Access first worksheet | |
const worksheet = workbook.getWorksheets().get(0); | |
// Access the cell which contains conditional formatting databar | |
const cell = worksheet.getCells().get("C1"); | |
// Create and get the conditional formatting of the worksheet | |
const idx = worksheet.getConditionalFormattings().add(); | |
const fcc = worksheet.getConditionalFormattings().get(idx); | |
fcc.addCondition(AsposeCells.FormatConditionType.DataBar); | |
fcc.addArea(AsposeCells.CellArea.createCellArea("C1", "C4")); | |
// Access the conditional formatting databar | |
const dbar = fcc.get(0).getDataBar(); | |
// Create image or print options | |
const opts = new AsposeCells.ImageOrPrintOptions(); | |
opts.setImageType(AsposeCells.ImageType.Png); | |
// Get the image bytes of the databar | |
const imgBytes = dbar.toImage(cell, opts); | |
// Write image bytes on the disk | |
fs.writeFileSync(path.join(outputDir, "outputGenerateDatabarImage.png"), imgBytes); |