Free Support Forum - aspose.com

Right align picture in numeric cell

Hi,

I'am having a problem making af cell containing a number and a picture at the right edge. Whatever I do, the picture is allways placed at the left edge in front of the number. I can't get the pictures Right property to work.

My code looks like this:
First I format the cell, next I put the number and finally I insert the picture.

Worksheet currentSheet = excelApplication.Worksheets[0];
int i = excelApplication.Styles.Add();
Style tmpStyle = excelApplication.StylesIdea;
tmpStyle.Number = 4;
tmpStyle.Borders.SetStyle(CellBorderType.Thin);
tmpStyle.Borders.DiagonalStyle = CellBorderType.None;
tmpStyle.IsTextWrapped=true;
tmpStyle.HorizontalAlignment = TextAlignmentType.Right;
currentSheet.Cells[rowNumber, byteColumn].Style = tmpStyle;

currentSheet.Cells[rowNumber, byteColumn].PutValue(doubleVal);

Stream input=request.GetResponse().GetResponseStream();
byte[] data = new byte[10000];
int readBytes = input.Read(data, 0, data.Length);
MemoryStream stream = new MemoryStream(data, 0, readBytes);
int picturePos = currentSheet.Pictures.Add(rowNumber, columnNumber, stream);
Picture pic = currentSheet.Pictures[picturePos];
pic.Right = 5;

Please try:

pic.Left = 20;

I can't make it work. What ever I do I can't get the gif picture in the cell on the right side of the number. Do you have a simple example that can help me?

Kind regards

Thomas

A sample can be downloaded at http://www.aspose.com/Products/Aspose.Excel/Fixes/GIFPos.zip

I've downloaded the zip file and made some corrections to get the code running in my environment.

Excel.SetLicense("C:\\inetpub\\wwwroot\\3924bio\\DANSKEBANK\\bio\\Olap\\Licenses\\Aspose.Excel.lic");
Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
FileStream fs = new FileStream("c:\\tmp\\gifpos\\logo.gif", FileMode.Open, FileAccess.Read);
int pos = sheet.Pictures.Add(0, 0, fs);
Picture pic = sheet.Pictures[pos];
pic.Left = 20;

sheet.Cells["a1"].PutValue(123);

excel.Save("c:\\tmp\\book1.xls",FileFormatType.Excel97);


But still the gif is located to the left off the "123". Have you viewed the book1 spreadsheet? The gif location is also static. If I change the column width to a very little number the gif moves into the column to the right! Why doesn't pic.Right work?

What I'm trying to do is to format each cell as: [number][gif] dynamically. Hoping that the 2 componts will keep there relatively position.



Thomas

Hi Thomas,

Now I fully understand your need. Please try the following code:

Excel.SetLicense(“C:\inetpub\wwwroot\3924bio\DANSKEBANK\bio\Olap\Licenses\Aspose.Excel.lic”);
Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
FileStream fs = new FileStream(“c:\tmp\gifpos\logo.gif”, FileMode.Open, FileAccess.Read);
int pos = sheet.Pictures.Add(0, 0, fs);
Picture pic = sheet.Pictures[pos];
pic.Left = 30;

sheet.Cells[“a1”].PutValue(123);

sheet.Cells[“a1”].Style.HorizontalAlignment = TextAlignmentType.Left;

excel.Save(“c:\tmp\book1.xls”,FileFormatType.Excel97);

The image option is “Move but don’t size with cells” by default.

Sorry, that I keep asking but we are allmost there. Can I change the default image option from Aspose? And finally, I would like to have both number and gif aligned to the right, but if I change the textalignment to right, number and gif overlap.


.Thomas

Hi Thomas,

Could you create a sample file and send it to me? So I can undstand what’s your need.

Currently Aspose.Excel doesn’t support to change the image option. I will add it in later release.