Is there a way to take an image of an excel file without using office.interop dlls ? I succeeded to embed an excel file into a word document, but i need to show an image of this excel file on the word document. Using filestream, i can read any image and embed into the word document using open xml. The last thing who rest is creating an image from an excel file.
1
votes
1 Answers
1
votes
SpreadsheetGear 2012 for .NET can do that:
using SpreadsheetGear;
...
// Open workbook (SpreadsheetGear supports both XLS and XLSX/XLSM file formats)
IWorkbook workbook = Factory.GetWorkbook(@"C:\path\to\workbook.xlsx");
IWorksheet worksheet = workbook.Worksheets["Sheet1"];
// Create Image class, passing in desired range to render
SpreadsheetGear.Drawing.Image image = new SpreadsheetGear.Drawing.Image(worksheet.Cells["A1:D10"]);
// Create Bitmap of range
System.Drawing.Bitmap bitmap = image.GetBitmap();
// ... Insert into Word ...
The Image class also accepts IShape and IChart objects if you wish to render images of those objects instead. Once you have a System.Drawing.Bitmap you can presumably do whatever you want with it, including inserting into a Word document. You can find additional samples on the Excel Chart and Range Imaging Samples page.
Disclaimer: I work for SpreadsheetGear.