Skip to content

Commit 2d80491

Browse files
authored
Merge pull request #214 from SyncfusionExamples/966429-ExcelToImageMauiExample
966429-Add UG for converting Excel document to Image in .NET MAUI
2 parents 21a56ea + 330839b commit 2d80491

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1601
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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", "{E853FA99-0761-4807-B8CF-BD1B21BEBBDF}"
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+
{E853FA99-0761-4807-B8CF-BD1B21BEBBDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E853FA99-0761-4807-B8CF-BD1B21BEBBDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E853FA99-0761-4807-B8CF-BD1B21BEBBDF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{E853FA99-0761-4807-B8CF-BD1B21BEBBDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{E853FA99-0761-4807-B8CF-BD1B21BEBBDF}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{E853FA99-0761-4807-B8CF-BD1B21BEBBDF}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {2654F362-EEC3-4AC5-86DB-84DC0B03FE65}
26+
EndGlobalSection
27+
EndGlobal
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:ConvertExcelToImage"
5+
x:Class="ConvertExcelToImage.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace ConvertExcelToImage
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="ConvertExcelToImage.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:ConvertExcelToImage"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="ConvertExcelToImage">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ConvertExcelToImage
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>ConvertExcelToImage</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>ConvertExcelToImage</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.convertexceltoimage</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
34+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
35+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
37+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
39+
</PropertyGroup>
40+
41+
<ItemGroup>
42+
<!-- App Icon -->
43+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
44+
45+
<!-- Splash Screen -->
46+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
47+
48+
<!-- Images -->
49+
<MauiImage Include="Resources\Images\*" />
50+
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />
51+
52+
<!-- Custom Fonts -->
53+
<MauiFont Include="Resources\Fonts\*" />
54+
55+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
56+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
57+
</ItemGroup>
58+
59+
<ItemGroup>
60+
<None Remove="InputTemplate.xlsx" />
61+
</ItemGroup>
62+
63+
<ItemGroup>
64+
<EmbeddedResource Include="InputTemplate.xlsx" />
65+
</ItemGroup>
66+
67+
<ItemGroup>
68+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
69+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
70+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
71+
<PackageReference Include="Syncfusion.XlsIORenderer.NET" Version="*" />
72+
</ItemGroup>
73+
74+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
5+
<ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework>
6+
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<None Update="App.xaml">
10+
<SubType>Designer</SubType>
11+
</None>
12+
<None Update="AppShell.xaml">
13+
<SubType>Designer</SubType>
14+
</None>
15+
<None Update="MainPage.xaml">
16+
<SubType>Designer</SubType>
17+
</None>
18+
<None Update="Platforms\Windows\App.xaml">
19+
<SubType>Designer</SubType>
20+
</None>
21+
<None Update="Platforms\Windows\Package.appxmanifest">
22+
<SubType>Designer</SubType>
23+
</None>
24+
<None Update="Resources\Styles\Colors.xaml">
25+
<SubType>Designer</SubType>
26+
</None>
27+
<None Update="Resources\Styles\Styles.xaml">
28+
<SubType>Designer</SubType>
29+
</None>
30+
</ItemGroup>
31+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="ConvertExcelToImage.MainPage">
5+
<ScrollView>
6+
<VerticalStackLayout
7+
Padding="30,0"
8+
Spacing="25">
9+
<Image
10+
Source="dotnet_bot.png"
11+
HeightRequest="185"
12+
Aspect="AspectFit"
13+
SemanticProperties.Description="dot net bot in a race car number eight" />
14+
15+
<Label
16+
Text="Hello, World!"
17+
Style="{StaticResource Headline}"
18+
SemanticProperties.HeadingLevel="Level1" />
19+
20+
<Label
21+
Text="Welcome to &#10;.NET Multi-platform App UI"
22+
Style="{StaticResource SubHeadline}"
23+
SemanticProperties.HeadingLevel="Level2"
24+
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
25+
26+
<Button
27+
x:Name="CounterBtn"
28+
Text="Convert Excel to Image"
29+
SemanticProperties.Hint="Counts the number of times you click"
30+
Clicked="convertExceltoImage_Click"
31+
HorizontalOptions="Fill" />
32+
</VerticalStackLayout>
33+
</ScrollView>
34+
</ContentPage>
35+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Syncfusion.XlsIO;
2+
using Syncfusion.XlsIORenderer;
3+
using System.IO;
4+
using System.Reflection;
5+
using ConvertExcelToImage.SaveServices;
6+
7+
namespace ConvertExcelToImage
8+
{
9+
public partial class MainPage : ContentPage
10+
{
11+
int count = 0;
12+
13+
public MainPage()
14+
{
15+
InitializeComponent();
16+
}
17+
18+
private void convertExceltoImage_Click(object sender, EventArgs e)
19+
{
20+
using (ExcelEngine excelEngine = new ExcelEngine())
21+
{
22+
Syncfusion.XlsIO.IApplication application = excelEngine.Excel;
23+
24+
Assembly executingAssembly = typeof(App).GetTypeInfo().Assembly;
25+
using (Stream inputStream = executingAssembly.GetManifestResourceStream("ConvertExcelToImage.InputTemplate.xlsx"))
26+
{
27+
IWorkbook workbook = application.Workbooks.Open(inputStream);
28+
IWorksheet worksheet = workbook.Worksheets[0];
29+
30+
//Initialize XlsIO renderer.
31+
application.XlsIORenderer = new XlsIORenderer();
32+
33+
//Create the MemoryStream to save the image.
34+
MemoryStream imageStream = new MemoryStream();
35+
36+
//Save the converted image to MemoryStream.
37+
worksheet.ConvertToImage(worksheet.UsedRange, imageStream);
38+
imageStream.Position = 0;
39+
40+
//save and Launch the Image
41+
SaveService saveService = new();
42+
saveService.SaveAndView("ExcelToImage.Jpeg", "application/jpeg", imageStream);
43+
}
44+
}
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)