prashanth_prolific_coder

based on parameters et by user I extract image in a binary format.

extaract image out of it

now i want to add that to excel sheet.

am able to open excel write text to it etc.but how about an image

Code Block

byte[] data = null;

byte[] data=((Config.Enterprise.SolutionLayoutVisio)solution.Layout).RawFile;

data = ((Config.Enterprise.SolutionLayoutVisio)solution.Layout).TopologySnapshot;

GetImage(data);

xlWrapper.WriteCellImage(4, 3, (Excel.OLEObject)image);

return result

Code Block

private Image GetImage(byte[] data)

{

Image _image = null;

if (data != null && data.Length > 0)

{

//HttpContext.Current.Response.ContentType = "image/jpg";

using (MemoryStream memoryStream = new MemoryStream(data, true))

{

_image = Image.FromStream(memoryStream, true, true);

//_image.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);

//_image.Dispose();

}

}

return _image;

Code Block

public void WriteCellImage(int row, int column, Excel.OLEObject diagram)

{

VerifyState();

WriteCellImage(_xlCurrentSheet, row, column, diagram);

}

private void WriteCellImage(Excel.Worksheet worksheet, int row, int column, Excel.OLEObject value)

{

Debug.Assert(worksheet != null);

worksheet.Cells[row, column] = value;

}

Any help would be greatly apprecaited.Been bugging me for quite a bit.




Re: Visual Studio Tools for Office based on parameters et by user I extract image in a binary format.

Cindy Meister

Excel (and Word, for that matter) have no way for you to "stream" anything other than text from memory into the opened file. You need to persist your image to disk, then use the AddPicture method of the Shapes object to load the file into the worksheet.






Re: Visual Studio Tools for Office based on parameters et by user I extract image in a binary format.

prashanth_prolific_coder

That was what I finally concluded...

Code Block

string path = (@"C:\Documents and Settings\prolific_coder\My Documents\My Pictures\jgs.jpg");

_xlCurrentSheet.Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 1000, 1000, 700, 700);

Now I want to add the pic to a specific cell location in the tab sheet.isee that i am able to add it to the sheet but not where I wanted it to be.

Can i Specify the cell location as in row and column instead of in points.

Thanks






Re: Visual Studio Tools for Office based on parameters et by user I extract image in a binary format.

Cindy Meister

prashanth_prolific_coder wrote:

Now I want to add the pic to a specific cell location in the tab sheet.isee that i am able to add it to the sheet but not where I wanted it to be.

Can i Specify the cell location as in row and column instead of in points.

Not directly. But you can reference the target range's Left and Top properties. For example, suppose I want to use the currently selected cell in the application. Then the following sample code will do the trick. Or, you could set a particular cell, such as Cells[1,3] to be the range.

Code Block

Excel.Range rng = (Excel.Range)xl.ActiveCell;

object lft = rng.Left;

object tp = rng.Top;

float celllft = Convert.ToSingle(lft);

float celltp = Convert.ToSingle(tp);

string path = @"C:\Pictures\Cluny.jpg";

ws.Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse,

Microsoft.Office.Core.MsoTriState.msoTrue,

celllft, celltp, 100f, 100f);