إنشاء صور أشرطة بيانات التنسيق الشرطي
Contents
[
Hide
]
في بعض الأحيان ، تحتاج إلى إنشاء صور لأشرطة بيانات التنسيق الشرطي. يمكنك استخدام Aspose.CellsDataBar.oImage () طريقة لتوليد هذه الصور. يوضح هذا المقال كيفية إنشاء صورة DataBar باستخدام Aspose.Cells.
ينشئ نموذج التعليمات البرمجية التالي صورة DataBar للخلية C1. أولاً ، يصل إلى كائن شرط التنسيق للخلية ، ثم من هذا الكائن ، يصل إلى ملفشريط البيانات وجوه واستخداماتهToImage ()طريقة لتوليد صورة الخلية. أخيرًا ، يحفظ الصورة على القرص.
This file contains 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 | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Create workbook object from source excel file | |
Workbook workbook = new Workbook(sourceDir + "sampleGenerateDatabarImage.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the cell which contains conditional formatting databar | |
Cell cell = worksheet.Cells["C1"]; | |
// Create and get the conditional formatting of the worksheet | |
int idx = worksheet.ConditionalFormattings.Add(); | |
FormatConditionCollection fcc = worksheet.ConditionalFormattings[idx]; | |
fcc.AddCondition(FormatConditionType.DataBar); | |
fcc.AddArea(CellArea.CreateCellArea("C1", "C4")); | |
// Access the conditional formatting databar | |
DataBar dbar = fcc[0].DataBar; | |
// Create image or print options | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.ImageType = Drawing.ImageType.Png; | |
// Get the image bytes of the databar | |
byte[] imgBytes = dbar.ToImage(cell, opts); | |
// Write image bytes on the disk | |
File.WriteAllBytes(outputDir + "outputGenerateDatabarImage.png", imgBytes); |