DrawObjectEventHandler sınıfını kullanarak PDF ye render ederken DrawObject ve Bound almak
Olası Kullanım Senaryoları
Aspose.Cells, DrawObjectEventHandler isimli soyut bir sınıf sunar, kullanıcı Draw() metodunu uygulayabilir ve Excel dosyasını PDF veya görüntüye render ederken DrawObjectEventHandler metodunu kullanarak DrawObject ve Bound alabilir. Aşağıdaki, Draw() metodunun parametrelerinin kısa bir açıklaması yer almaktadır.
-
drawObject: Render edilirken DrawObject başlatılır ve döndürülür
-
x: DrawObject‘nın solu
-
y: DrawObject‘nın üstü
-
width:DrawObject‘nın genişliği
-
height: DrawObject‘nın yüksekliği
Eğer Excel dosyasını PDF’e render ediyorsanız, PdfSaveOptions.DrawObjectEventHandler ile DrawObjectEventHandler sınıfını kullanabilirsiniz. Benzer şekilde, eğer Excel dosyasını Görüntüye render ediyorsanız, ImageOrPrintOptions.DrawObjectEventHandler ile DrawObjectEventHandler sınıfını kullanabilirsiniz.
DrawObjectEventHandler sınıfını kullanarak PDF’ye render ederken DrawObject ve Bound almak
Lütfen aşağıdaki örnek kodu inceleyin. Örnek Excel dosyasını yükler ve çıktı PDF’sini kaydeder. PDF’ye render ederken, PdfSaveOptions.DrawObjectEventHandler özelliğini kullanır ve mevcut hücrelerin ve nesnelerin (örneğin görüntüler) DrawObject ve Bound değerlerini yakalar. Eğer DrawObject tipi Hücre ise, Bound ve StringValue’yi yazdırır. Ve eğer DrawObject tipi Görüntü ise, Bound ve Şekil Adını yazdırır. Daha fazla yardım için aşağıdaki örnek kodun konsol çıktısına bakınız.
Örnek Kod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Aspose.Cells.Rendering; | |
namespace Aspose.Cells.Examples.CSharp.Rendering | |
{ | |
class GetDrawObjectAndBoundUsingDrawObjectEventHandler | |
{ | |
//Implement the concrete class of DrawObjectEventHandler | |
class clsDrawObjectEventHandler : DrawObjectEventHandler | |
{ | |
public override void Draw(DrawObject drawObject, float x, float y, float width, float height) | |
{ | |
Console.WriteLine(""); | |
//Print the coordinates and the value of Cell object | |
if (drawObject.Type == DrawObjectEnum.Cell) | |
{ | |
Console.WriteLine("[X]: " + x + " [Y]: " + y + " [Width]: " + width + " [Height]: " + height + " [Cell Value]: " + drawObject.Cell.StringValue); | |
} | |
//Print the coordinates and the shape name of Image object | |
if (drawObject.Type == DrawObjectEnum.Image) | |
{ | |
Console.WriteLine("[X]: " + x + " [Y]: " + y + " [Width]: " + width + " [Height]: " + height + " [Shape Name]: " + drawObject.Shape.Name); | |
} | |
Console.WriteLine("----------------------"); | |
} | |
} | |
public static void Run() | |
{ | |
//Load sample Excel file | |
Workbook wb = new Workbook("sampleGetDrawObjectAndBoundUsingDrawObjectEventHandler.xlsx"); | |
//Specify Pdf save options | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
//Assign the instance of DrawObjectEventHandler class | |
opts.DrawObjectEventHandler = new clsDrawObjectEventHandler(); | |
//Save to Pdf format with Pdf save options | |
wb.Save("outputGetDrawObjectAndBoundUsingDrawObjectEventHandler.pdf", opts); | |
} | |
} | |
} |
Konsol Çıktısı
[X]: 153.6035 [Y]: 82.94118 [Width]: 103.2035 [Height]: 14.47059 [Cell Value]: This is sample text.
----------------------
[X]: 267.6917 [Y]: 153.4853 [Width]: 160.4491 [Height]: 128.0647 [Shape Name]: Sun
----------------------