Skip to content

Commit 21a56ea

Browse files
authored
Merge pull request #212 from SyncfusionExamples/964307-ExcelToImageWinFormsExample
964307-Add UG for converting Excel document to Image in Windows Forms
2 parents 87c43d6 + 28e9e1b commit 21a56ea

File tree

12 files changed

+510
-0
lines changed

12 files changed

+510
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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>{DDE2395A-AE2F-4C3B-B427-E3045FE2E702}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>Convert_Excel_to_Image</RootNamespace>
10+
<AssemblyName>Convert Excel to Image</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Deployment" />
43+
<Reference Include="System.Drawing" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Windows.Forms" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="Form1.cs">
50+
<SubType>Form</SubType>
51+
</Compile>
52+
<Compile Include="Form1.Designer.cs">
53+
<DependentUpon>Form1.cs</DependentUpon>
54+
</Compile>
55+
<Compile Include="Program.cs" />
56+
<Compile Include="Properties\AssemblyInfo.cs" />
57+
<EmbeddedResource Include="Properties\Resources.resx">
58+
<Generator>ResXFileCodeGenerator</Generator>
59+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
60+
<SubType>Designer</SubType>
61+
</EmbeddedResource>
62+
<Compile Include="Properties\Resources.Designer.cs">
63+
<AutoGen>True</AutoGen>
64+
<DependentUpon>Resources.resx</DependentUpon>
65+
</Compile>
66+
<None Include="packages.config" />
67+
<None Include="Properties\Settings.settings">
68+
<Generator>SettingsSingleFileGenerator</Generator>
69+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
70+
</None>
71+
<Compile Include="Properties\Settings.Designer.cs">
72+
<AutoGen>True</AutoGen>
73+
<DependentUpon>Settings.settings</DependentUpon>
74+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
75+
</Compile>
76+
</ItemGroup>
77+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
78+
</Project>

Getting Started/Windows Forms/Convert Excel to Image/Convert Excel to Image/Form1.Designer.cs

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Syncfusion.XlsIO;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Data;
6+
using System.Drawing;
7+
using System.Drawing.Imaging;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Text;
11+
using System.Threading.Tasks;
12+
using System.Windows.Forms;
13+
14+
namespace Convert_Excel_to_Image
15+
{
16+
public partial class Form1 : Form
17+
{
18+
public Form1()
19+
{
20+
InitializeComponent();
21+
}
22+
23+
private void btnConvert_Click(object sender, EventArgs e)
24+
{
25+
using (ExcelEngine excelEngine = new ExcelEngine())
26+
{
27+
IApplication application = excelEngine.Excel;
28+
application.DefaultVersion = ExcelVersion.Xlsx;
29+
FileStream excelStream = new FileStream("Sample.xlsx", FileMode.Open, FileAccess.Read);
30+
IWorkbook workbook = application.Workbooks.Open(excelStream);
31+
IWorksheet worksheet = workbook.Worksheets[0];
32+
33+
//Convert the Excel to Image
34+
Image image = worksheet.ConvertToImage(1, 1, 20, 4);
35+
36+
//Save the image as jpeg
37+
image.Save("Sample.Jpeg", ImageFormat.Jpeg);
38+
}
39+
40+
//Launch the Image file
41+
System.Diagnostics.Process process = new System.Diagnostics.Process();
42+
process.StartInfo = new System.Diagnostics.ProcessStartInfo(Path.GetFullPath(@"../../Sample.Jpeg")) { UseShellExecute = true };
43+
process.Start();
44+
}
45+
}
46+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using System.Windows.Forms;
6+
7+
namespace Convert_Excel_to_Image
8+
{
9+
internal static class Program
10+
{
11+
/// <summary>
12+
/// The main entry point for the application.
13+
/// </summary>
14+
[STAThread]
15+
static void Main()
16+
{
17+
Application.EnableVisualStyles();
18+
Application.SetCompatibleTextRenderingDefault(false);
19+
Application.Run(new Form1());
20+
}
21+
}
22+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Convert Excel to Image")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Convert Excel to Image")]
13+
[assembly: AssemblyCopyright("Copyright © 2025")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("dde2395a-ae2f-4c3b-b427-e3045fe2e702")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
[assembly: AssemblyVersion("1.0.0.0")]
33+
[assembly: AssemblyFileVersion("1.0.0.0")]

Getting Started/Windows Forms/Convert Excel to Image/Convert Excel to Image/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)