How to save images from Excel without using clipboard in C #?

I studied this quite extensively, but did not find exactly what I am looking for. Two methods found:

1: Using Microsoft.Office.Interop.Excel, iterate over the forms of the workbook, then copy the images to the clipboard, and then take the clipboard data and put it in a bitmap and then save that bitmap. The problem with this method is the clipboard. We would like this to be used in a multi-threaded environment and be afraid of clipboard problems between threads. We would prefer not to deal with clipboard locks.

2: Save the file as an .HTML file, then grab the images from the "_files" folder created where the document was saved. The problem is that two images are created for each image (1 high resolution, 1 low level), and there is no good way to determine which images have low resolution and which images have high resolution, since they are all called image ### and some files list them high, low, high, low, and some list them high, high, low, low. Using all of these files is slow and takes up space, which is not ideal. I could check the images for aspect ratios, but this is obviously not very good, because several images can have the same aspect ratio.

Is there a way to parse Excel.Shape directly as a bitmap (or any image format) without using the clipboard? It seems like there should be a way because the Shape.CopyPicture method can send it to the clipboard in image format. Otherwise, is there a way to do something like number 2 without getting duplicates? I would prefer a solution that avoids the use of third-party libraries.

Thanks.

+7
source share
1 answer

I assume that you are using Excel 2007/2010 format. Each Excel 2007/2010 file is a zip file! Just rename the Excel.xlsx file to Excel.zip . Then unzip the file to a folder. Images are located in the "/ xl / media" folder.

Try it out manually. Knowing this, it is easy to automate this by writing a C # program for this.

+25
source

All Articles