VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
In This Topic
XLSX: Render pages of XLSX document
In This Topic
Here is C#/VB.NET code that shows how to open XLSX document using XlsxDecoder class, render all pages of XLSX document and save rendered images to PNG files:
/// <summary>
/// Converts pages of XLSX document to PNG files.
/// </summary>
public static void ConvertXlsxToPng(string xlsxFileName)
{
    // specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
    Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
    // specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
    //Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();

    // create image collection
    using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
    {
        // add XLSX document to the image collection
        images.Add(xlsxFileName);

        // create PNG encoder
        using (Vintasoft.Imaging.Codecs.Encoders.PngEncoder pngEncoder =
            new Vintasoft.Imaging.Codecs.Encoders.PngEncoder())
        {
            // for each page in XLSX document
            for (int i = 0; i < images.Count; i++)
            {
                // save rendered image to a PNG file
                images[i].Save(string.Format("page{0}.png", i), pngEncoder);
            }
        }

        // dispose images
        images.ClearAndDisposeItems();
    }
}
''' <summary>
''' Converts pages of XLSX document to PNG files.
''' </summary>
Public Shared Sub ConvertXlsxToPng(xlsxFileName As String)
    ' specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
    Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault()
    ' specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
    'Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault()

    ' create image collection
    Using images As New Vintasoft.Imaging.ImageCollection()
        ' add XLSX document to the image collection
        images.Add(xlsxFileName)

        ' create PNG encoder
        Using pngEncoder As New Vintasoft.Imaging.Codecs.Encoders.PngEncoder()
            ' for each page in XLSX document
            For i As Integer = 0 To images.Count - 1
                ' save rendered image to a PNG file
                images(i).Save(String.Format("page{0}.png", i), pngEncoder)
            Next
        End Using

        ' dispose images
        images.ClearAndDisposeItems()
    End Using
End Sub



Here is C#/VB.NET code that shows how to open XLSX document using XlsxDocument class, render all pages of XLSX document and save rendered images to PNG files:
/// <summary>
/// Renders all pages of XLSX document and saves rendered images to PNG files.
/// </summary>
/// <param name="filePath">A path to XLSX file.</param>
public static void RenderAndSaveXlsxPages(string filePath)
{
    // open XLSX document
    using (Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument xlsxDocument =
        new Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
    {
        // for each XLSX page
        for (int i = 0; i < xlsxDocument.Pages.Count; i++)
        {
            // render XLSX page
            using (Vintasoft.Imaging.VintasoftImage renderedPage = xlsxDocument.Pages[i].Render())
            {
                // save rendered image to a PNG file
                renderedPage.Save(string.Format("page{0}.png", i));
            }
        }
    }
}
''' <summary>
''' Renders all pages of XLSX document and saves rendered images to PNG files.
''' </summary>
''' <param name="filename">A name of XLSX file.</param>
Public Shared Sub RenderAndSaveXlsxPages(filename As String)
    ' open XLSX document
    Using xlsxDocument As New Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)
        ' for each XLSX page
        For i As Integer = 0 To xlsxDocument.Pages.Count - 1
            ' render XLSX page
            Using renderedPage As Vintasoft.Imaging.VintasoftImage = xlsxDocument.Pages(i).Render()
                ' save rendered image to a PNG file
                renderedPage.Save(String.Format("page{0}.png", i))
            End Using
        Next
    End Using
End Sub