Problems with autosize

Hi Sjoerd,

Thanks for your posting and using Aspose.Cells.

This issue is logged as a Normal issue. If you like, you can post in Priority Forum, then we will increase the priority of this issue. However, increasing the priority does not guarantee a fix but escalates the issue. Priority issues are processed first than Normal issues.

We cannot provide you any expected date for this issue to be fixed at this moment. However, we have already logged your comments and requested the development team to provide any ETA or update regarding this issue.

Hi,

Thanks for using Aspose.Cells.

We have fixed the issues CELLSNET-42104 and CELLSNET-42401.

Please download and try this fix: Aspose.Cells
for .NET v8.0.1.3
and let us know your feedback.

We have fixed the bugs except related to output file xlsb.

Hi,

Thanks for using Aspose.Cells.

Please download and try this fix: Aspose.Cells
for .NET v8.0.1.3
for the issue id: CELLSNET-42235.

You can resize the text using following.

1. If set IsTextWrapped to false. Don’t specify limited scope, the text will not be wrapped until meets newline character.


textBox.TextFrame.AutoSize =
true;

textBox.IsTextWrapped = false;

int[] size = textBox.CalculateTextSize();

textBox.Height = size[1];

textBox.Width = size[0];



2. If set IsTextWrapped to true. At the same time sets width of shape.CalculateTextSize() method will ensure the text does not extend out of the fixed width and the height is a variable value.

textBox.TextFrame.AutoSize = true;

textBox.IsTextWrapped = true;

//If IsTextWrapped is true, must set the width of shape to a proper fixed value.

//In this case, CalculateTextSize()[0] is equals shape.Width.

textbox.Width = 400;

int[] size = textBox.CalculateTextSize();

textBox.Height = size[1];

textBox.Width = size[0];

Hi Shakeel,

The attached version 8.0.1.3 is for .NET 2.

I can’t compile against it.

Could you please send me through the version for .NET 3.5 please.

Thanks,

Mike

Hi Mike,

Thanks for your posting and using Aspose.Cells.

I have forwarded your request to development team to provide you NET 3.5 Aspose.Cells Dll. Once, it is available for you, we will let you know asap.

Hi Mike,

Thanks for using Aspose.Cells.

Please download and try the latest .NET 3.5 version: Aspose.Cells
for .NET v8.0.1.3 (NET 3.5)
for your needs.

Hi Shakeel,

I have tested this latest version against the original attachment (see earlier in this post) demonstrating the problem, with the changes you suggested re setting the Width of the Text Box.

I note the same problems and thus believe it is still not fixed.

Regards,

Mike

Hi Mike,

Thanks for your feedback and using Aspose.Cells.

I have tested this issue with the latest version: Aspose.Cells
for .NET v8.0.1.3
and found that all the output files (xlsx, xps, pdf) except (xlsb) are working fine. Which is correct. Because we are still working on xlsb issue.

I have attached the output files for your reference.

Hi Shakeel,

I tried the following code, and the Text Box height when you open it (and click on it when you open the file in MS Excel) is still not correct. Saving to .Xlsx.

This is with version 8.0.1.3 of Aspose Cells

Am I doing something wrong…???

private void TextBoxShapeAutoHeightIssue()
{
Workbook testWorkbook = new Workbook();
Worksheet testWorksheet = testWorkbook.Worksheets[0];
Cells testCells = testWorksheet.Cells;
int iWidth = testCells.GetColumnWidthPixel(1);
iWidth += testCells.GetColumnWidthPixel(2);
Shape testShape = testWorksheet.Shapes.AddTextBox(1, 0, 1, 0, 0, 0);
testCells.SetColumnWidthPixel(5, 300);
testCells[15, 5].Value = “Text Box Height - After Creation”;
testCells[15, 6].Value = testShape.Height;
MsoTextFrame testTextFrame = testShape.TextFrame;
testTextFrame.BottomMarginPt = 0;
testTextFrame.LeftMarginPt = 0;
testTextFrame.RightMarginPt = 0;
testTextFrame.TopMarginPt = 0;
// SET AUTO SIZE
testTextFrame.AutoSize = true;
testTextFrame.IsAutoMargin = false;
testShape.Text = “The TextBox in the created spreadsheet does not set the height of the TextBox correctly when the TextFrame.AutoSize property is set to true.”;
testShape.Placement = PlacementType.Move;
testShape.IsLocked = false;
testShape.IsPrintable = true;
testShape.IsLocked = false;
testShape.IsLockAspectRatio = true;
testShape.IsTextWrapped = true;
testShape.LineFormat.IsVisible = false;
testShape.TextOrientationType = TextOrientationType.NoRotation;
testShape.TextHorizontalAlignment = TextAlignmentType.Justify;
testShape.TextVerticalAlignment = TextAlignmentType.Top;
testShape.Width = iWidth;
int[] size = testShape.CalculateTextSize();
// SET THE Height and Width as returned by .CalculateTextSize()
testShape.Height = size[1];
// testShape.Width = size[0];
testCells[17, 5].Value = “Text Box Height - After Setting Properties”;
testCells[17, 6].Value = testShape.Height;
// testWorkbook.Save(@“C:\TextBoxHeightIssue.Xlsb”, SaveFormat.Xlsb);
// Process.Start(@“C:\TextBoxHeightIssue.Xlsb”);

        testWorkbook.Save(@"C:\TextBoxHeightIssue.Xlsx", SaveFormat.Xlsx);
        Process.Start(@"C:\TextBoxHeightIssue.Xlsx");
    }

Hi Mike,

Thanks for your sample code and using Aspose.Cells.

We were able to observe this issue using your sample code with the latest version: Aspose.Cells
for .NET v8.0.1.3
. Shape.CalculateTextSize() does not return correct height when TextFrame.AutoSize property is set to true.

Although, the sample code mentioned in this post: 504550 generates correct results.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

I have attached the output xlsx file and screenshot for a reference.

C#


private void TextBoxShapeAutoHeightIssue()

{

Workbook testWorkbook = new Workbook();

Worksheet testWorksheet = testWorkbook.Worksheets[0];

Cells testCells = testWorksheet.Cells;

int iWidth = testCells.GetColumnWidthPixel(1);

iWidth += testCells.GetColumnWidthPixel(2);

Shape testShape = testWorksheet.Shapes.AddTextBox(1, 0, 1, 0, 0, 0);

testCells.SetColumnWidthPixel(5, 300);

testCells[15, 5].Value = “Text Box Height - After Creation”;

testCells[15, 6].Value = testShape.Height;

MsoTextFrame testTextFrame = testShape.TextFrame;

testTextFrame.BottomMarginPt = 0;

testTextFrame.LeftMarginPt = 0;

testTextFrame.RightMarginPt = 0;

testTextFrame.TopMarginPt = 0;

// SET AUTO SIZE

testTextFrame.AutoSize = true;

testTextFrame.IsAutoMargin = false;

testShape.Text = “The TextBox in the created spreadsheet does not set the height of the TextBox correctly when the TextFrame.AutoSize property is set to true.”;

testShape.Placement = PlacementType.Move;

testShape.IsLocked = false;

testShape.IsPrintable = true;

testShape.IsLocked = false;

testShape.IsLockAspectRatio = true;

testShape.IsTextWrapped = true;

testShape.LineFormat.IsVisible = false;

testShape.TextOrientationType = TextOrientationType.NoRotation;

testShape.TextHorizontalAlignment = TextAlignmentType.Justify;

testShape.TextVerticalAlignment = TextAlignmentType.Top;

testShape.Width = iWidth;

int[] size = testShape.CalculateTextSize();

// SET THE Height and Width as returned by .CalculateTextSize()

testShape.Height = size[1];

// testShape.Width = size[0];

testCells[17, 5].Value = “Text Box Height - After Setting Properties”;

testCells[17, 6].Value = testShape.Height;

// testWorkbook.Save(@“C:\TextBoxHeightIssue.Xlsb”, SaveFormat.Xlsb);

// Process.Start(@“C:\TextBoxHeightIssue.Xlsb”);


testWorkbook.Save(@“TextBoxHeightIssue.Xlsx”, SaveFormat.Xlsx);

// Process.Start(@“C:\TextBoxHeightIssue.Xlsx”);

}

Thanks Shakeel.

Best wishes to the team finding out what is going wrong here and getting a solution.

As always,

Best Regards,

Mike

Hi Mike,

Thanks for your posting and using Aspose.Cells.

As the workbook and the shape are created by Aspose.Cells API, we can’t know proper font of shape when CalculateTextSize() method is called.

So we can fix the issue by setting the font before calling CalculateTextSize() method.

C#


testShape.Font.Name = “Calibri”;

testShape.Font.Size = 11;

int[] size = testShape.CalculateTextSize();



Here is a complete code. I have attached the output file for your reference.

Complete Code:
private void TextBoxShapeAutoHeightIssue()
{
Workbook testWorkbook = new Workbook();
Worksheet testWorksheet = testWorkbook.Worksheets[0];
Cells testCells = testWorksheet.Cells;
int iWidth = testCells.GetColumnWidthPixel(1);
iWidth += testCells.GetColumnWidthPixel(2);
Shape testShape = testWorksheet.Shapes.AddTextBox(1, 0, 1, 0, 0, 0);
testCells.SetColumnWidthPixel(5, 300);
testCells[15, 5].Value = "Text Box Height - After Creation";
testCells[15, 6].Value = testShape.Height;
MsoTextFrame testTextFrame = testShape.TextFrame;
testTextFrame.BottomMarginPt = 0;
testTextFrame.LeftMarginPt = 0;
testTextFrame.RightMarginPt = 0;
testTextFrame.TopMarginPt = 0;
// SET AUTO SIZE
testTextFrame.AutoSize = true;
testTextFrame.IsAutoMargin = false;
testShape.Text = "The TextBox in the created spreadsheet does not set the height of the TextBox correctly when the TextFrame.AutoSize property is set to true.";
testShape.Placement = PlacementType.Move;
testShape.IsLocked = false;
testShape.IsPrintable = true;
testShape.IsLocked = false;
testShape.IsLockAspectRatio = true;
testShape.IsTextWrapped = true;
testShape.LineFormat.IsVisible = false;
testShape.TextOrientationType = TextOrientationType.NoRotation;
testShape.TextHorizontalAlignment = TextAlignmentType.Justify;
testShape.TextVerticalAlignment = TextAlignmentType.Top;
testShape.Width = iWidth;
testShape.Font.Name = "Calibri";
testShape.Font.Size = 11;

int[] size = testShape.CalculateTextSize();
// SET THE Height and Width as returned by .CalculateTextSize()
testShape.Height = size[1];
// testShape.Width = size[0];
testCells[17, 5].Value = "Text Box Height - After Setting Properties";
testCells[17, 6].Value = testShape.Height;
//testWorkbook.Save(@"C:\TextBoxHeightIssue.Xlsb", SaveFormat.Xlsb);
//Process.Start(@"C:\TextBoxHeightIssue.Xlsb");

testWorkbook.Save(@"TextBoxHeightIssue.Xlsx", SaveFormat.Xlsx);
//Process.Start(@"C:\TextBoxHeightIssue.Xlsx");
}

The issues you have found earlier (filed as CELLSNET-42401;CELLSNET-42104) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Shakeel,

I have implemented Aspose Cells 8.0.2 and done some initial testing with this version in respect of the Text Box issue. So far all looks ok.

Will keep testing and let you know if any additional issues show up.

Thanks,

Mike

Hi Mike,

Thanks for your feedback and using Aspose.Cells.

It is good to know that everything is working good at your end and this issue is resolved with the latest version. Let us know if you encounter any other issue related to this issue, we will look into it and help you further.