We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to generate and display Excel files in thumbnail view ?

Platform: WPF |
Control: SfSpreadsheet |
Published Date: September 27, 2018 |
Last Revised Date: September 27, 2018

This article explains creating thumbnail views of Excel files and open the corresponding excel file using SfSpreadsheet control when clicking the thumbnail image.

Creating thumbnail images from Excel files

You can generate the thumbnail image from Excel file by using XlsIO ‘ConvertToImage()’ worksheet method. Please refer worksheet to image conversion help documentation for more information. You can get the code snippets regarding this below,

 

C#:

DirectoryInfo directory = new DirectoryInfo(@"..\..\ExcelFiles");

 

foreach (var file in directory.GetFiles())

{

   ExcelEngine excelEngine = new ExcelEngine();

   IApplication application = excelEngine.Excel;

   IWorkbook workbook = application.Workbooks.Open(file.FullName);

   IWorksheet worksheet = workbook.Worksheets[0];

   System.Drawing.Image image = worksheet.ConvertToImage(1, 1, worksheet.UsedRange.LastRow + 1, worksheet.UsedRange.LastColumn + 1, ImageType.Bitmap, null);

   image.Save(@"..\..\ExcelFiles\Thumbnails\" +    Path.GetFileNameWithoutExtension(file.Name)+ ".png", ImageFormat.Png);

   workbook.Close();

   excelEngine.Dispose();

}

 

Opening Excel file in SfSpreadsheet control from thumbnail view

Once images generated for corresponding Excel files, we can load the images in thumbnail view. When you click thumbnail image from view, the corresponding excel files will be loaded in SfSpreadsheet control.

C#:

private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

{

    if ((sender as StackPanel).DataContext is Model)

    {

        Model selectedSpreadsheet = (sender as StackPanel).DataContext as Model;

        spreadsheet.Open(@"..\..\ExcelFiles\"+  System.IO.Path.GetFileNameWithoutExtension(selectedSpreadsheet.ImageName) + ".xlsx");

    }

}

 

We have created sample application which is generate the images from given Excel files and arranged that in thumbnail view along with SfSpreadsheet preview.

 

Sample link: ThumbnailsDemo_WPF

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile