Çalışma Sayfasını Farklı Görüntü Formatlarına Dönüştürme

Çalışma Sayfasını Görüntüye Dönüştürme

Çalışma sayfaları, çözümlemek istediğiniz verileri içerir. Örneğin, bir çalışma sayfası parametreler, toplamlar, yüzdeler, istisnalar ve hesaplamalar içerebilir.

Bir geliştirici olarak, çalışma sayfalarını resim olarak sunmanız gerekebilir. Örneğin, bir uygulamada veya web sayfasında bir çalışma sayfasının görüntüsünü kullanmanız gerekebilir. Microsoft Word belgesine, PDF dosyasına, PowerPoint sunumuna veya başka bir belge türüne resim eklemek isteyebilirsiniz. Basitçe söylemek gerekirse, başka bir yerde kullanabilmeniz için bir çalışma sayfasının görüntü olarak işlenmesini istiyorsunuz.

Aspose.Cells, Excel çalışma sayfalarının resimlere dönüştürülmesini destekler. Bu özelliği kullanmak için içe aktarmanız gerekir.Aspose.Cells.RenderingProgramınıza veya projenize ad alanı. Oluşturma ve yazdırma için çeşitli değerli sınıflara sahiptir, örneğin,ISheetRenderIImageOrPrintOptionsve diğerleri.

Aspose.Cells.Rendering.ISheetRender sınıfı, görüntü olarak işlenecek bir çalışma sayfasını temsil eder. Aşırı yüklenmiş bir yöntemi vardır,Hayal etmek, bir çalışma sayfasını farklı özniteliklere veya seçeneklere sahip görüntü dosyalarına dönüştürebilir. Çeşitli görüntü formatları desteklenir, örneğin, BMP, PNG, GIF, JPG, JPEG, TIFF, EMF.

Aşağıdaki kod parçacığı, bir Excel dosyasındaki bir çalışma sayfasının bir görüntü dosyasına nasıl dönüştürüleceğini gösterir.

PNG Formatı

Lütfen aşağıdaki örnek koda bakın,örnek excel dosyası , veçıktı PNG Görseller.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path.
StringPtr srcDir = new String("..\\Data\\01_SourceDirectory\\");
// Output directory path.
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\");
// Path of input Excel file.
StringPtr sampleConvertingWorksheetToDifferentImageFormats = srcDir->StringAppend(new String("sampleConvertingWorksheetToDifferentImageFormats.xlsx"));
// Create an empty workbook.
intrusive_ptr<Aspose::Cells::IWorkbook> workbook = Factory::CreateIWorkbook(sampleConvertingWorksheetToDifferentImageFormats);
// Access first worksheet.
intrusive_ptr<Aspose::Cells::IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Create image or print options object.
intrusive_ptr<Aspose::Cells::Rendering::IImageOrPrintOptions> imgOptions = Factory::CreateIImageOrPrintOptions();
// Specify the image format.
imgOptions->SetImageFormat(Aspose::Cells::Systems::Drawing::Imaging::ImageFormat::GetPng());
// Specify horizontal and vertical resolution
imgOptions->SetHorizontalResolution(200);
imgOptions->SetVerticalResolution(200);
// Render the sheet with respect to specified image or print options.
intrusive_ptr<Aspose::Cells::Rendering::ISheetRender> sr = Factory::CreateISheetRender(worksheet, imgOptions);
// Get page count.
Aspose::Cells::Systems::Int32 pageCount = sr->GetPageCount();
// Create string builder object for string concatenations.
intrusive_ptr<Aspose::Cells::Systems::Text::StringBuilder> sb = new Aspose::Cells::Systems::Text::StringBuilder();
// Render each page to png image one by one.
for (int i = 0; i < pageCount; i++)
{
// Clear string builder and create output image path with string concatenations.
sb->Clear();
sb->Append(outDir);
sb->Append((StringPtr)new String("outputConvertingWorksheetToImagePNG_"));
sb->Append(i);
sb->Append((StringPtr)new String(".png"));
// Get the output image path.
StringPtr outputPNG = sb->ToString();
// Convert worksheet to png image.
sr->ToImage(i, outputPNG);
}

TIFF Formatı

Lütfen aşağıdaki örnek koda bakın,örnek excel dosyası , veçıktı TIFF Resim.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path.
StringPtr srcDir = new String("..\\Data\\01_SourceDirectory\\");
// Output directory path.
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\");
// Path of input Excel file.
StringPtr sampleConvertingWorksheetToDifferentImageFormats = srcDir->StringAppend(new String("sampleConvertingWorksheetToDifferentImageFormats.xlsx"));
// Create an empty workbook.
intrusive_ptr<Aspose::Cells::IWorkbook> workbook = Factory::CreateIWorkbook(sampleConvertingWorksheetToDifferentImageFormats);
// Access first worksheet.
intrusive_ptr<Aspose::Cells::IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Create image or print options object.
intrusive_ptr<Aspose::Cells::Rendering::IImageOrPrintOptions> imgOptions = Factory::CreateIImageOrPrintOptions();
// Specify the image format.
imgOptions->SetImageFormat(Aspose::Cells::Systems::Drawing::Imaging::ImageFormat::GetTiff());
// Specify horizontal and vertical resolution
imgOptions->SetHorizontalResolution(200);
imgOptions->SetVerticalResolution(200);
// Render the sheet with respect to specified image or print options.
intrusive_ptr<Aspose::Cells::Rendering::ISheetRender> sr = Factory::CreateISheetRender(worksheet, imgOptions);
// Get the output image path.
StringPtr outputTiff = outDir->Append((StringPtr)new String("outputConvertingWorksheetToImageTiff.tiff"));
// Convert worksheet to tiff image.
sr->ToTiff(outputTiff);

Çalışma Sayfasını SVG’e Dönüştürme

SVG, Ölçeklenebilir Vektör Grafikleri anlamına gelir. SVG, iki boyutlu vektör grafikleri için XML standartlarına dayalı bir özelliktir. World Wide Web Consortium (W3C) tarafından 1999’dan beri geliştirilmekte olan açık bir standarttır.

Aspose.Cells for C++, 18.5.0 sürümünden itibaren çalışma sayfalarını SVG görüntüsüne dönüştürebilmiştir.

Bu özelliği kullanmak için Aspose.Cells.Rendering ad alanını programınıza veya projenize aktarın. Oluşturma ve yazdırma için birkaç değerli sınıfı vardır, örneğin ISheetRender, IImageOrPrintOptions ve diğerleri.

Aspose.Cells.Rendering.IImageOrPrintOptions sınıfı, çalışma sayfasının SVG biçiminde kaydedileceğini belirtir. Aşağıdaki kod parçacığı, bir Excel dosyasındaki bir çalışma sayfasının SVG görüntü dosyasına nasıl dönüştürüleceğini gösterir.

Lütfen aşağıdaki örnek koda bakın,örnek excel dosyası , veçıktı SVG Görseller.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path.
StringPtr srcDir = new String("..\\Data\\01_SourceDirectory\\");
// Output directory path.
StringPtr outDir = new String("..\\Data\\02_OutputDirectory\\");
// Path of input Excel file.
StringPtr sampleConvertingWorksheetToDifferentImageFormats = srcDir->StringAppend(new String("sampleConvertingWorksheetToDifferentImageFormats.xlsx"));
// Create an empty workbook.
intrusive_ptr<Aspose::Cells::IWorkbook> workbook = Factory::CreateIWorkbook(sampleConvertingWorksheetToDifferentImageFormats);
// Access first worksheet.
intrusive_ptr<Aspose::Cells::IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Create image or print options object.
intrusive_ptr<Aspose::Cells::Rendering::IImageOrPrintOptions> imgOptions = Factory::CreateIImageOrPrintOptions();
// Specify horizontal and vertical resolution
imgOptions->SetHorizontalResolution(200);
imgOptions->SetVerticalResolution(200);
// Specify the save format.
imgOptions->SetSaveFormat(Aspose::Cells::SaveFormat::SaveFormat_SVG);
// Render the sheet with respect to specified image or print options.
intrusive_ptr<Aspose::Cells::Rendering::ISheetRender> sr = Factory::CreateISheetRender(worksheet, imgOptions);
// Get page count.
Aspose::Cells::Systems::Int32 pageCount = sr->GetPageCount();
// Create string builder object for string concatenations.
intrusive_ptr<Aspose::Cells::Systems::Text::StringBuilder> sb = new Aspose::Cells::Systems::Text::StringBuilder();
// Render each page to png image one by one.
for (int i = 0; i < pageCount; i++)
{
// Clear string builder and create output image path with string concatenations.
sb->Clear();
sb->Append(outDir);
sb->Append((StringPtr)new String("outputConvertingWorksheetToImageSVG_"));
sb->Append(i);
sb->Append((StringPtr)new String(".svg"));
// Get the output image path.
StringPtr outputSVG = sb->ToString();
// Convert worksheet to tiff image.
sr->ToImage(i, outputSVG);
}