|
5 | 5 | public class UnitTest1
|
6 | 6 | {
|
7 | 7 |
|
8 |
| - string testFilePath = "/Users/fahadadeelqazi/Downloads/test_fahad_new_protected111.xlsx"; |
| 8 | + string testFilePath = "/Users/fahadadeelqazi/Downloads/test_fahad_new_protected_image.xlsx"; |
9 | 9 | private string imageInputPath = "/Users/fahadadeelqazi/Downloads/ImageCells.png";
|
10 | 10 | string outputDirectory = "/Users/fahadadeelqazi/Downloads/";
|
11 | 11 |
|
@@ -294,44 +294,51 @@ public void Test_ExtractImages()
|
294 | 294 | {
|
295 | 295 | using (Workbook wb = new Workbook(testFilePath))
|
296 | 296 | {
|
| 297 | + |
297 | 298 | var worksheet = wb.Worksheets[0];
|
298 |
| - var images = worksheet.ExtractImages(); |
| 299 | + var image = new Image(imageInputPath); |
| 300 | + |
| 301 | + worksheet.AddImage(image, 6, 1, 8, 3); |
| 302 | + |
| 303 | + wb.Save(testFilePath); |
| 304 | + |
| 305 | + Workbook wb1 = new Workbook(testFilePath); |
| 306 | + |
| 307 | + var worksheet1 = wb1.Worksheets[0]; |
| 308 | + |
| 309 | + var images = worksheet1.ExtractImages(); |
299 | 310 |
|
300 | 311 | Assert.IsTrue(images.Any(), "No images extracted from the worksheet.");
|
301 | 312 |
|
302 | 313 | if (!Directory.Exists(outputDirectory))
|
303 | 314 | Directory.CreateDirectory(outputDirectory);
|
304 | 315 |
|
305 |
| - foreach (var image in images) |
| 316 | + foreach (var extracted_image in images) |
306 | 317 | {
|
307 |
| - var outputFilePath = Path.Combine(outputDirectory, $"Image_{Guid.NewGuid()}.{image.Extension}"); |
| 318 | + var outputFilePath = Path.Combine(outputDirectory, $"Image_{Guid.NewGuid()}.{extracted_image.Extension}"); |
308 | 319 |
|
309 | 320 | using (var fileStream = File.Create(outputFilePath))
|
310 | 321 | {
|
311 |
| - image.Data.CopyTo(fileStream); |
| 322 | + extracted_image.Data.CopyTo(fileStream); |
312 | 323 | }
|
313 | 324 |
|
314 | 325 | // Assert that the image has been saved correctly
|
315 | 326 | Assert.IsTrue(File.Exists(outputFilePath), $"Image not found at {outputFilePath}");
|
316 | 327 | }
|
317 | 328 | }
|
318 |
| - } |
319 |
| - |
320 |
| - |
321 |
| - |
322 | 329 |
|
323 | 330 |
|
| 331 | + } |
324 | 332 |
|
325 | 333 |
|
326 | 334 |
|
327 | 335 | [TestCleanup]
|
328 | 336 | public void Cleanup()
|
329 | 337 | {
|
330 |
| - // Clean up test artifacts |
331 |
| - //if (File.Exists(testFilePath)) |
332 |
| - //File.Delete(testFilePath); |
| 338 | + //Clean up test artifacts |
| 339 | + if (File.Exists(testFilePath)) |
| 340 | + File.Delete(testFilePath); |
333 | 341 |
|
334 |
| - |
335 | 342 | }
|
336 | 343 |
|
337 | 344 | }
|
0 commit comments