How to use oleobject


#1

Hi,Laurence,I want to convert a xls file to a oleobject and insert it to an worksheet special in other xls file.

How to do it i should?


#2

I had sent a new version and sample code to Timons. Do you work with him?

Following is a piece of sample code:

FileStream fs = File.OpenRead("d:\\logo.jpg");
byte[] imageData = new Byte[fs.Length];
fs.Read(imageData, 0, imageData.Length);
fs.Close();
fs = File.OpenRead("d:\\test\\book1.xls");
byte[] objectData = new Byte[fs.Length];
fs.Read(objectData, 0, objectData.Length);
fs.Close();

Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
sheet.OleObjects.Add(3, 3, 150, 150);

sheet.OleObjects[0].ImageData = imageData; // image shown in Excel
sheet.OleObjects[0].ObjectData = objectData; // embedded ole object data
sheet.OleObjects[0].Border.IsVisible = false;
excel.Save("d:\\test\\abc.xls");

#3

Thank’s very much,i will test the sample!