Skip to content

Commit 7ae1977

Browse files
authored
Merge pull request #298 from SyncfusionExamples/992569-CorruptedImg
Documentation(992569): Add example for how to remove the corrupted embedded images before saving the excel file
2 parents 4ef5fc7 + 37a4589 commit 7ae1977

5 files changed

Lines changed: 80 additions & 0 deletions

File tree

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.36202.13 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoveCorruptedImages", "RemoveCorruptedImages\RemoveCorruptedImages.csproj", "{EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}"
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+
{EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.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 = {C7DF1415-C535-4573-BAC4-E9A9624F18AE}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.

FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Output/.gitkeep

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Syncfusion.XlsIO;
2+
3+
namespace RemoveCorruptedImages
4+
{
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
using (ExcelEngine excelEngine = new ExcelEngine())
10+
{
11+
IApplication application = excelEngine.Excel;
12+
application.DefaultVersion = ExcelVersion.Xlsx;
13+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
14+
foreach (IWorksheet sheet in workbook.Worksheets)
15+
{
16+
for (int i = 0; i < sheet.Pictures.Count; i++)
17+
{
18+
if (sheet.Pictures[i].Picture.ImageData.Length <= 0)
19+
{
20+
// Remove the corrupted image.
21+
Console.WriteLine("Image removed due to corruption");
22+
sheet.Pictures[i].Remove();
23+
}
24+
}
25+
}
26+
27+
//Save the workbook
28+
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
29+
}
30+
}
31+
}
32+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<None Update="Output\*">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Data\*">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
23+
</Project>

0 commit comments

Comments
 (0)