Skip to content

Commit 87c43d6

Browse files
authored
Merge pull request #213 from SyncfusionExamples/964304-ExcelToImageWPF
964304-Add UG for converting Excel document to Image in WPF
2 parents df960ca + b4f9a17 commit 87c43d6

File tree

13 files changed

+520
-0
lines changed

13 files changed

+520
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36127.28 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConvertExcelToImage", "ConvertExcelToImage\ConvertExcelToImage.csproj", "{509E3317-4319-4B16-9A38-AEBE9DDB42FE}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{509E3317-4319-4B16-9A38-AEBE9DDB42FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{509E3317-4319-4B16-9A38-AEBE9DDB42FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{509E3317-4319-4B16-9A38-AEBE9DDB42FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{509E3317-4319-4B16-9A38-AEBE9DDB42FE}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {68C34065-4AA5-4AAA-B58D-028E51F0954D}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="ConvertExcelToImage.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:ConvertExcelToImage"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace ConvertExcelToImage
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{509E3317-4319-4B16-9A38-AEBE9DDB42FE}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>ConvertExcelToImage</RootNamespace>
10+
<AssemblyName>ConvertExcelToImage</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Drawing" />
41+
<Reference Include="System.Xml" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Core" />
44+
<Reference Include="System.Xml.Linq" />
45+
<Reference Include="System.Data.DataSetExtensions" />
46+
<Reference Include="System.Net.Http" />
47+
<Reference Include="System.Xaml">
48+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
49+
</Reference>
50+
<Reference Include="WindowsBase" />
51+
<Reference Include="PresentationCore" />
52+
<Reference Include="PresentationFramework" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<ApplicationDefinition Include="App.xaml">
56+
<Generator>MSBuild:Compile</Generator>
57+
<SubType>Designer</SubType>
58+
</ApplicationDefinition>
59+
<Page Include="MainWindow.xaml">
60+
<Generator>MSBuild:Compile</Generator>
61+
<SubType>Designer</SubType>
62+
</Page>
63+
<Compile Include="App.xaml.cs">
64+
<DependentUpon>App.xaml</DependentUpon>
65+
<SubType>Code</SubType>
66+
</Compile>
67+
<Compile Include="MainWindow.xaml.cs">
68+
<DependentUpon>MainWindow.xaml</DependentUpon>
69+
<SubType>Code</SubType>
70+
</Compile>
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Compile Include="Properties\AssemblyInfo.cs">
74+
<SubType>Code</SubType>
75+
</Compile>
76+
<Compile Include="Properties\Resources.Designer.cs">
77+
<AutoGen>True</AutoGen>
78+
<DesignTime>True</DesignTime>
79+
<DependentUpon>Resources.resx</DependentUpon>
80+
</Compile>
81+
<Compile Include="Properties\Settings.Designer.cs">
82+
<AutoGen>True</AutoGen>
83+
<DependentUpon>Settings.settings</DependentUpon>
84+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
85+
</Compile>
86+
<EmbeddedResource Include="Properties\Resources.resx">
87+
<Generator>ResXFileCodeGenerator</Generator>
88+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
89+
</EmbeddedResource>
90+
<None Include="packages.config" />
91+
<None Include="Properties\Settings.settings">
92+
<Generator>SettingsSingleFileGenerator</Generator>
93+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
94+
</None>
95+
</ItemGroup>
96+
<ItemGroup>
97+
<None Include="App.config" />
98+
</ItemGroup>
99+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100+
</Project>
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Window x:Class="ConvertExcelToImage.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:ConvertExcelToImage"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800">
9+
<Grid>
10+
<Button Click="btnConvert_Click" VerticalAlignment="Center" Height="30" BorderBrush="LightBlue" HorizontalAlignment="Center" Width="150">
11+
<Button.Background>
12+
<LinearGradientBrush EndPoint="0.5,-0.04" StartPoint="0.5,1.04">
13+
<GradientStop Color="#FFD9E9F7" Offset="0"/>
14+
<GradientStop Color="#FFEFF8FF" Offset="1"/>
15+
</LinearGradientBrush>
16+
</Button.Background>
17+
<StackPanel Orientation="Horizontal" Height="23" Margin="0,0,0,-2.52" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="100" RenderTransformOrigin="0.5,0.5">
18+
<StackPanel.RenderTransform>
19+
<TransformGroup>
20+
<ScaleTransform/>
21+
<SkewTransform/>
22+
<RotateTransform Angle="-0.226"/>
23+
<TranslateTransform/>
24+
</TransformGroup>
25+
</StackPanel.RenderTransform>
26+
<Image Name="image2" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" />
27+
<TextBlock Text="Excel to Image" Height="38" Width="187" Margin="0,4,0,3" TextWrapping="WrapWithOverflow" />
28+
</StackPanel>
29+
</Button>
30+
</Grid>
31+
</Window>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Syncfusion.XlsIO;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Drawing.Imaging;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows;
10+
using System.Windows.Controls;
11+
using System.Windows.Data;
12+
using System.Windows.Documents;
13+
using System.Windows.Input;
14+
using System.Windows.Media;
15+
using System.Windows.Media.Imaging;
16+
using System.Windows.Navigation;
17+
18+
19+
namespace ConvertExcelToImage
20+
{
21+
/// <summary>
22+
/// Interaction logic for MainWindow.xaml
23+
/// </summary>
24+
public partial class MainWindow : Window
25+
{
26+
public MainWindow()
27+
{
28+
InitializeComponent();
29+
}
30+
31+
private void btnConvert_Click(object sender, RoutedEventArgs e)
32+
{
33+
using (ExcelEngine excelEngine = new ExcelEngine())
34+
{
35+
IApplication application = excelEngine.Excel;
36+
application.DefaultVersion = ExcelVersion.Xlsx;
37+
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
38+
IWorkbook workbook = application.Workbooks.Open(excelStream);
39+
IWorksheet worksheet = workbook.Worksheets[0];
40+
41+
//Convert the Excel to image
42+
System.Drawing.Image image = worksheet.ConvertToImage(1, 1, 20, 4);
43+
44+
//Save the image as jpeg
45+
image.Save("Sample.Jpeg", ImageFormat.Jpeg);
46+
}
47+
48+
//Launch the Image
49+
System.Diagnostics.Process process = new System.Diagnostics.Process();
50+
process.StartInfo = new System.Diagnostics.ProcessStartInfo(Path.GetFullPath(@"../../Sample.Jpeg")) { UseShellExecute = true };
51+
process.Start();
52+
53+
}
54+
}
55+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("ConvertExcelToImage")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("ConvertExcelToImage")]
15+
[assembly: AssemblyCopyright("Copyright © 2025")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
[assembly: AssemblyVersion("1.0.0.0")]
52+
[assembly: AssemblyFileVersion("1.0.0.0")]

Getting Started/WPF/Convert Excel to Image/ConvertExcelToImage/Properties/Resources.Designer.cs

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)