Skip to content

Commit

Permalink
Merge pull request #37 from SyncfusionExamples/Excel-to-Thumbnail-Image
Browse files Browse the repository at this point in the history
Excel to Thumbnail image conversion sample
  • Loading branch information
Mohan2401 authored Jun 23, 2023
2 parents 2a6b0e8 + bc26ee7 commit 815e1ab
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33513.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excel To Thumbnail Image", "Excel To Thumbnail Image\Excel To Thumbnail Image.csproj", "{40357E15-2E82-4E6C-9501-6BE095EEB722}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{40357E15-2E82-4E6C-9501-6BE095EEB722}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40357E15-2E82-4E6C-9501-6BE095EEB722}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40357E15-2E82-4E6C-9501-6BE095EEB722}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40357E15-2E82-4E6C-9501-6BE095EEB722}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {38AB5DF7-3343-4550-BD1E-5F293A0C913D}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Excel_to_Thumbnail</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="22.1.34" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.IO;
using Syncfusion.XlsIO;
using Syncfusion.XlsIORenderer;

namespace Excel_To_Thumbnail_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 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();
}
}
}

0 comments on commit 815e1ab

Please sign in to comment.