-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from SyncfusionExamples/Excel-to-Thumbnail-Image
Excel to Thumbnail image conversion sample
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Real Time Examples in Excel/Excel To Thumbnail Image/Excel To Thumbnail Image.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+12.1 KB
...amples in Excel/Excel To Thumbnail Image/Excel To Thumbnail Image/Data/InputTemplate.xlsx
Binary file not shown.
14 changes: 14 additions & 0 deletions
14
...n Excel/Excel To Thumbnail Image/Excel To Thumbnail Image/Excel To Thumbnail Image.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
44 changes: 44 additions & 0 deletions
44
Real Time Examples in Excel/Excel To Thumbnail Image/Excel To Thumbnail Image/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |