Skip to content

Commit 00c12ec

Browse files
authored
Merge pull request #363 from SyncfusionExamples/891655-CustomerSample
To add sample to convert Named range in worksheet to Image
2 parents 88d02f9 + 9e1d105 commit 00c12ec

6 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="NamedRange to Image/NamedRange to Image.csproj" />
3+
</Solution>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<RootNamespace>NamedRange_to_Image</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIORenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\*">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>

‎Worksheet to Image/Worksheet to Image/.NET/NamedRange to Image/NamedRange to Image/Output/.gitkeep‎

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Syncfusion.XlsIO;
2+
using Syncfusion.XlsIORenderer;
3+
4+
namespace NamedRange_to_Image
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
using (ExcelEngine excelEngine = new ExcelEngine())
11+
{
12+
IApplication application = excelEngine.Excel;
13+
application.DefaultVersion = ExcelVersion.Xlsx;
14+
FileStream inputStream = new FileStream(Path.GetFullPath(@"../../../Data/Sample.xlsb"), FileMode.Open, FileAccess.Read);
15+
IWorkbook workbook = application.Workbooks.Open(inputStream);
16+
17+
IName name = workbook.Names["Range1"];
18+
19+
IRange range = name.RefersToRange;
20+
21+
//Initialize XlsIORenderer
22+
application.XlsIORenderer = new XlsIORenderer();
23+
24+
#region Save
25+
//Saving the workbook
26+
using FileStream outputStream = new FileStream("../../../Output/Output.png", FileMode.Create, FileAccess.Write);
27+
28+
// Convert the named range to an image.
29+
range.Worksheet.ConvertToImage(range, outputStream);
30+
31+
#endregion
32+
33+
//Dispose streams
34+
outputStream.Dispose();
35+
inputStream.Dispose();
36+
}
37+
}
38+
}
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Convert a Named Range to an Image
2+
3+
This sample demonstrates how to convert a named range in an XLSB workbook to a PNG image using Syncfusion XlsIO and XlsIORenderer.
4+
5+
## Requirements
6+
7+
- Syncfusion.XlsIO
8+
- Syncfusion.XlsIORenderer
9+
10+
## Process
11+
12+
1. Opens the `Sample.xlsb` workbook.
13+
2. Retrieves the named range `Range1`.
14+
3. Converts the named range to an image.
15+
4. Saves the rendered image as `Output.png`.
16+
17+
## Input
18+
19+
Place the `Sample.xlsb` workbook in the `Data` folder and ensure that it contains a named range called `Range1`.
20+
21+
## Output
22+
23+
The converted image is saved as:
24+
25+
`Output/Output.png`

0 commit comments

Comments
 (0)