Comment width problem

Hi

I am explicitly setting the width and height when creating a comment. The height takes effectine, but the width is apparently ignored - the yellow comment box extends off the right hand side of the page. I am using the following code:

int commentIndex = ws.Comments.Add( 1,1);

Comment comment = ws.Comments[commentIndex];

comment.WidthCM = 2.0;

comment.HeightCM = 2.0;

comment.Note ="Hello";

What am I doing wrong?

Thanks

Alan

Hi Alan,

I use the following test code and it works fine.

Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];
int commentIndex = ws.Comments.Add( 1,1);

Comment comment = ws.Comments[commentIndex];

comment.WidthCM = 2.0;

comment.HeightCM = 2.0;

comment.Note ="Hello";

wb.Save("d:\\test\\abc.xls");
Please check the attached file.

Which version of Aspose.Cells are you using?

Sorry, Laurence, I cannot reproduce the problem when I use the code in a fresh test application. I guess there must be something corrupt about my dev application that is causing this undesirable behaviour. Thanks for your time, anyway.

I have now figured out how to reproduce the problem. It occurs when I save the workbook object to a MemoryStream, then later try to save the workbook object to a disk file. When the disk file is opened in Excel, the cell comments render incorrectly.

Conversely, if I save the workbook object directly to disk, then open the file in Excel, the cell comments render correctly. As far as I can tell, the cell comments are the only Excel feature that are adversely affected by first saving to a stream.

To reproduce the problem, use the code below:

private void commentprob_Click( object sender, EventArgs e )

{

Workbook excel = new Workbook();

// Set column widths.

excel.Worksheets[0].Cells.SetColumnWidth( 0, 11 );

excel.Worksheets[0].Cells.SetColumnWidth( 1, 15 );

// Write content to cells.

excel.Worksheets[0].Cells[0, 0].PutValue( "Text A" );

excel.Worksheets[0].Cells[0, 1].PutValue( "Text B" );

// Write a cell comment.

int commentIndex = excel.Worksheets[0].Comments.Add( 0, 0 );

Comment comment = excel.Worksheets[0].Comments[commentIndex];

comment.WidthCM = 2.0;

comment.HeightCM = 2.0;

comment.Note = "hello";

// Save workbook to a memory stream.

System.IO.MemoryStream memStream = new System.IO.MemoryStream();

excel.Save( memStream, FileFormatType.Default );

// Further processing may be done here...

// Save workbook to a disk file.

excel.Open( memStream, FileFormatType.Default );

excel.Save( "c:\\aspose.xls", FileFormatType.Default );

}

Note also that if you make the column widths 11 each, the comment renders correctly. Any idea what's going on?

Thanks

Alan

Strange enough. There is no difference when saving to stream or saving to file. Anyway, I will check and fix this issue ASAP. Thanks for your information.

I figure it out. Please try this attached version.

Thanks, Laurence. This fixes the problem.