Skip to content

Commit

Permalink
Merge pull request #116 from SyncfusionExamples/Kb-Samples
Browse files Browse the repository at this point in the history
Add Kb samples for converting Excel images to GIF.
  • Loading branch information
Mohan2401 authored Jul 23, 2024
2 parents c7cecb5 + 070966e commit 328e66f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Use Cases/Image to Gif/NET Standard/Image to Gif/Image to Gif.sln
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.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Image to Gif", "Image to Gif\Image to Gif.csproj", "{1ED29CD7-AA72-46E3-B532-E7429BED055F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1ED29CD7-AA72-46E3-B532-E7429BED055F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ED29CD7-AA72-46E3-B532-E7429BED055F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ED29CD7-AA72-46E3-B532-E7429BED055F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ED29CD7-AA72-46E3-B532-E7429BED055F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9122DE32-2608-472A-919F-2DC5B1DDEF6D}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Image_to_Gif</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.9.1" />
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="26.1.42" />
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
</ItemGroup>

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

namespace Image_to_Gif
{
class Program
{
public static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;

//Load an input template
using(FileStream file = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read))
{
IWorkbook workbook = application.Workbooks.Open(file);

using (MagickImageCollection collection = new MagickImageCollection())
{
for (int i = 0; i < workbook.Worksheets.Count; i++)
{
IWorksheet worksheet = workbook.Worksheets[i];

//Initialize XlsIORenderer
application.XlsIORenderer = new XlsIORenderer();

//Create a memory stream to save the image
using (MemoryStream stream = new MemoryStream())
{
//Convert worksheet to image and save it to stream
worksheet.ConvertToImage(1,1,27,11, stream);

//Set stream postition
stream.Position = 0;

//Load the image into MagickImage
MagickImage image = new MagickImage(stream);

//Add the image to the collection
collection.Add(image);
}
}

//Set the delay between frames (100 = 1 second)
foreach (MagickImage image in collection)
{
image.AnimationDelay = 100;
}

//Create an animated GIF
collection.Write(@"Output.gif");
}
}
}
}
}
}

0 comments on commit 328e66f

Please sign in to comment.