diff --git a/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages.sln b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages.sln new file mode 100644 index 00000000..bd406cb2 --- /dev/null +++ b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36202.13 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoveCorruptedImages", "RemoveCorruptedImages\RemoveCorruptedImages.csproj", "{EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC0341DA-AFC9-4B8E-ADB9-E1DBB28ED4B8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C7DF1415-C535-4573-BAC4-E9A9624F18AE} + EndGlobalSection +EndGlobal diff --git a/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Data/Input.xlsx b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Data/Input.xlsx new file mode 100644 index 00000000..a0e348be Binary files /dev/null and b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Data/Input.xlsx differ diff --git a/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Output/.gitkeep b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Program.cs b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Program.cs new file mode 100644 index 00000000..9386098b --- /dev/null +++ b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/Program.cs @@ -0,0 +1,32 @@ +using Syncfusion.XlsIO; + +namespace RemoveCorruptedImages +{ + class Program + { + public static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); + foreach (IWorksheet sheet in workbook.Worksheets) + { + for (int i = 0; i < sheet.Pictures.Count; i++) + { + if (sheet.Pictures[i].Picture.ImageData.Length <= 0) + { + // Remove the corrupted image. + Console.WriteLine("Image removed due to corruption"); + sheet.Pictures[i].Remove(); + } + } + } + + //Save the workbook + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); + } + } + } +} \ No newline at end of file diff --git a/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/RemoveCorruptedImages.csproj b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/RemoveCorruptedImages.csproj new file mode 100644 index 00000000..f0247a60 --- /dev/null +++ b/FAQ/Remove corrupted images/.NET/RemoveCorruptedImages/RemoveCorruptedImages/RemoveCorruptedImages.csproj @@ -0,0 +1,23 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + Always + + + Always + + + + \ No newline at end of file