4 Simple Steps to Create Thumbnail Images for Excel Documents in C#
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (180).NET Core  (28).NET MAUI  (223)Angular  (113)ASP.NET  (49)ASP.NET Core  (81)ASP.NET MVC  (87)Azure  (41)Black Friday Deal  (1)Blazor  (233)BoldSign  (14)DocIO  (24)Essential JS 2  (110)Essential Studio  (199)File Formats  (72)Flutter  (135)JavaScript  (226)Microsoft  (121)PDF  (83)Python  (1)React  (105)Streamlit  (1)Succinctly series  (131)Syncfusion  (958)TypeScript  (33)Uno Platform  (3)UWP  (3)Vue  (46)Webinar  (53)Windows Forms  (59)WinUI  (72)WPF  (162)Xamarin  (159)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (10)Business intelligence  (55)Button  (4)C#  (162)Chart  (145)Chart of the week  (57)Cloud  (15)Company  (440)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (73)Development  (675)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (13)Excel  (43)Extensions  (23)File Manager  (7)Gantt  (20)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (518)Mobile MVC  (9)OLAP server  (2)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (45)Performance  (13)PHP  (2)PivotGrid  (5)Predictive Analytics  (6)Report Server  (3)Reporting  (8)Reporting / Back Office  (9)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (5)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (32)Solution Services  (4)Spreadsheet  (11)SQL  (15)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (113)UI  (399)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (623)What's new  (335)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
4 Simple Steps to Create Thumbnail Images for Excel Documents in C#

4 Simple Steps to Create Thumbnail Images for Excel Documents in C#

In today’s digital age, visual representation is crucial in capturing attention and conveying information effectively. Whether working on a personal project or developing professional software, creating visually appealing thumbnail images can significantly enhance the user experience and facilitate more straightforward navigation.

This article will show you how to create a thumbnail image for an Excel document using the Syncfusion .NET Core Excel (XlsIO) Library in C#.

Enjoy a smooth experience with Syncfusion’s Excel Library! Get started with a few lines of code and without Microsoft or interop dependencies.

Creating thumbnail images for Excel documents using C#

Follow these steps to create a thumbnail image for an Excel document using the Syncfusion .NET Excel Library:

Note: If you are new to our Excel Library, our Getting Started guide is highly recommended.

  1. First, open Visual Studio and create a new .NET Core console application.Create a .NET Core console application
  2. Then, install the latest version of the Syncfusion.XlsIORenderer.Net.Core NuGet package.Install the Syncfusion.XlsIORenderer.Net.Core NuGet package
  3. Add the following code to the Program.cs file to convert an Excel document to an image.
    using (ExcelEngine excelEngine = new ExcelEngine())
    {
        IApplication application = excelEngine.Excel;
        application.DefaultVersion = ExcelVersion.Xlsx;
        FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
        IWorkbook workbook = application.Workbooks.Open(inputStream);
        IWorksheet sheet = workbook.Worksheets[0];
        
        //Initialize XlsIORenderer.
        application.XlsIORenderer = new XlsIORenderer();
        
        //Convert to image.
        MemoryStream outputStream = new MemoryStream();
        sheet.ConvertToImage(sheet.UsedRange, outputStream);
    }
  4. Then, add the following code to resize the image to thumbnail size.
    //Resize image to thumbnail size.
    System.Drawing.Image image = System.Drawing.Image.FromStream(outputStream);
    System.Drawing.Image thumbnail = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
    
    //Save image.
    thumbnail.Save("Image.png", System.Drawing.Imaging.ImageFormat.Png);
    Following is the complete code of the Program.cs file.
    using System;
    using System.IO;
    using Syncfusion.XlsIO;
    using Syncfusion.XlsIORenderer;
    
    namespace Excel_to_Image
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                using (ExcelEngine excelEngine = new ExcelEngine())
                {
                    IApplication application = excelEngine.Excel;
                    application.DefaultVersion = ExcelVersion.Xlsx;
                    FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
                    IWorkbook workbook = application.Workbooks.Open(inputStream);
                    IWorksheet sheet = workbook.Worksheets[0];
                    
                    //Initialize XlsIORenderer.
                    application.XlsIORenderer = new XlsIORenderer();
                    
                    //Convert to image.
                    MemoryStream outputStream = new MemoryStream();
                    sheet.ConvertToImage(sheet.UsedRange, outputStream);
                    
                    //Resize image to thumbnail size.
                    System.Drawing.Image image = System.Drawing.Image.FromStream(outputStream);
                    System.Drawing.Image thumbnail = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
                    
                    //Save the image.
                    thumbnail.Save("Image.png", System.Drawing.Imaging.ImageFormat.Png);
                }
                
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Image.png")
                {
                    UseShellExecute = true
                };
                process.Start();
            }
        }
    }
    Refer to the following images.
    Input Excel document
    Input Excel document
    Thumbnail image for the input Excel document
    Thumbnail image for the input Excel document

GitHub reference

You can download the example for creating thumbnail images for Excel documents on this GitHub page.

Immerse yourself in practical examples spotlighting the extraordinary features of Syncfusion’s C# Excel Library!

Conclusion

Thanks for reading! In this blog, we’ve seen how to create thumbnail images for Excel documents using the Syncfusion .NET Core Excel Library in C#. Take a moment to peruse the documentation, where you’ll find other features with accompanying code samples.

Using this library, you can also export Excel data to PDF,  data tables, CSV, TSV, HTML, collections of objects, ODS, JSON, and other file formats.

Are you already a Syncfusion subscriber? You can download the product setup here. If you’re not a Syncfusion subscriber, you can download a free 30-day trial to check out Essential Studio’s features.

Please let us know in the comments section below if you have any questions about these features. You can also contact us through our support forum, support portal, or feedback portal. We are always happy to assist you!

Don't settle for ordinary spreadsheet solutions. Switch to Syncfusion and upgrade the way you handle Excel files in your apps!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed