إنشاء صور أشرطة بيانات التنسيق الشرطي
Contents
[
Hide
]
في بعض الأحيان ، تحتاج إلى إنشاء صور لأشرطة بيانات التنسيق الشرطي. يمكنك استخدام Aspose.Cells[DataBar.toImage ()](https://reference.aspose.com/cells/java/com.aspose.cells/databar#toImage(com.aspose.cells.Cell,%20com.aspose.cells.ImageOrPrintOptions)طريقة لتوليد هذه الصور. يوضح هذا المقال كيفية إنشاء صورة DataBar باستخدام Aspose.Cells.
مثال
ينشئ نموذج التعليمات البرمجية التالي صورة DataBar للخلية C1. أولاً ، يصل إلى كائن شرط التنسيق للخلية ، ثم من هذا الكائن ، يصل إلى كائن DataBar ويستخدمDataBar.toImage () طريقة لتوليد صورة الخلية. أخيرًا ، يحفظ الصورة على القرص.
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-Java | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "sampleGenerateDatabarImage.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the cell which contains conditional formatting databar | |
Cell cell = worksheet.getCells().get("C1"); | |
// Create and get the conditional formatting of the worksheet | |
int idx = worksheet.getConditionalFormattings().add(); | |
FormatConditionCollection fcc = worksheet.getConditionalFormattings().get(idx); | |
fcc.addCondition(FormatConditionType.DATA_BAR); | |
fcc.addArea(CellArea.createCellArea("C1", "C4")); | |
// Access the conditional formatting databar | |
DataBar dbar = fcc.get(0).getDataBar(); | |
// Create image or print options | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setImageType(ImageType.PNG); | |
// Get the image bytes of the databar | |
byte[] imgBytes = dbar.toImage(cell, opts); | |
// Write image bytes on the disk | |
FileOutputStream out = new FileOutputStream(outputDir + "databar.png"); | |
out.write(imgBytes); | |
out.close(); | |
// save workbook with databars | |
workbook.save(outputDir + "databar.xlsx"); |