Our application has distribution functions. It takes several Excel 2007 tables, copies them into one sheet, and then sends them to users. The problem is that images and charts are not copied. I tried everything I could find here and various other sources, but, unfortunately, nothing works. Our application is written using VSTO, and I also tried OpenXML, but nothing works. In fact, an attempt to copy to OpenXML damaged files so much that Excel could not read or restore them. Here is the code that we use (note: with us, ExcelWrapper simply calls the same functions in Excel, but hides all optional elements).
private void CreateWorkbook(string filePath, string batchReportsPath) {
I tried every promising option and searched for both VSTO and OpenXML object models, and I'm at a dead end. The stackoverflow community, you are my only hope.
UPDATE:. Respondents' answers:
//Copy all the images, Charts, shapes foreach (Excel.Shape o in copySheet.Shapes) { if (o.Type == Microsoft.Office.Core.MsoShapeType.msoPicture) o.CopyPicture(); else o.Copy(); newWorkbook.Save(); }
You need to make a save after each copy to complete the paste. Thanks for your input.
source share