Row.GetPreferredHeight() does not return valid values for single line text

Posted by: krishna.vajja on 24 June 2020, 4:23 pm EST

  • Posted 24 June 2020, 4:23 pm EST

    Hi,
    We are facing an issue in using Row.GetPreferredHeight() method for increasing the row size as per the text length given.
    When there is a single line of text within the cell and we use GetPreferredHeight(), we could see the cell size is increased more than the height of the text. This issue also appears when we export the sheet into excel and pdf.
    But this works fine in case of multiline text within the cell.
    Help us resolve the issue at a high priority.
    In the screenshot below text of Notes 2 and 3 have correct height while 1, 2 and 5 are higher in size. This is also reflected in the exported excel and pdf files.

    Thanks,
    Krishna.
  • Marked as Answer

    Replied 25 June 2020, 12:50 am EST

    Hello Krishna,

    Can you please include the FarPoint.Win.TextRenderer assembly in your project's references along with using the following code and see if it helps:
    FarPoint.Win.Spread.CellType.GeneralCellType generalCellType = new FarPoint.Win.Spread.CellType.GeneralCellType();
    generalCellType.Multiline = true;
    fpSpread1.ActiveSheet.Rows[0].CellType = generalCellType;

    fpSpread1.ActiveSheet.Rows[0].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;
    fpSpread1.ActiveSheet.Rows[0].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;

    fpSpread1.ActiveSheet.Cells[0, 0].Value = "Single line text";

    fpSpread1.AsWorkbook().ActiveSheet.Rows.AutoFit();

    float height = fpSpread1.ActiveSheet.GetPreferredRowHeight(0);
    fpSpread1.ActiveSheet.Rows[0].Height = height;
    Regards,
    Ruchir
  • Replied 28 June 2020, 9:44 pm EST

    Hi,

    I tried the mentioned code but it didn't work. Please help in resolving the issue on high priority

    Regards,
    Krishna
  • Replied 29 June 2020, 10:48 pm EST

    Hello Krishna,

    I have forwarded your problem to the developer and requesting him to investigate [ID: 9247]. Will get back to you as soon as there is some information.

    Regards,
    Ruchir
  • Replied 5 July 2020, 6:20 pm EST

    Hi Ruchir,

    Thanks for investigating on the issue. Can you tell us the progress of the issue and estimated time for that to get resolved as this is an high priority for us.

    Regards,
    Krishna.
  • Replied 5 July 2020, 10:24 pm EST

    Hi Krishna,

    If the Fpspread.LegacyBehavior of spread in your project is None, you can follow the below code:
    fpSpread1.ActiveSheet.Cells[0, 0].Value = "Single line text";
    fpSpread1.AsWorkbook().ActiveSheet.Rows[0].AutoFit();
    Thanks,
    Ruchir
  • Replied 15 July 2020, 10:17 pm EST

    Hello Ruchir,
    Thanks for the above code.It worked for us partially.
    With the given code, the difference between the cell height and the text height is uniform across different types of cells in case of Exported Excel.
    But where as in our application, we can still see the difference between the cell height and the height of the text and it conducts very much differently wrt different types of cells.
    In the application, when wordwrap is set to true and we have single line of text the gap is increased compared to normal cells.
    Attaching the images for reference.
    Please help us solve the issue asap as we have to deliver it to our customers on priority.

    Thanks,
    Krishna.
  • Replied 15 July 2020, 10:16 pm EST

    On Sheet:

  • Replied 15 July 2020, 10:16 pm EST

    On Exported Sheet:
  • Replied 16 July 2020, 5:11 pm EST

    Hello Krishna,

    In that case, the problem seems specific to the Spread implementation in your application. As you mention that the suggestion works for export but not in your application and it's behavior is different for different cell types, can you please share a stripped down application for the same? It help us to share a solution tailored for your application.
    Additionally, please share the Spread.NET version you are using.

    With thanks,
    Ruchir
  • Replied 23 July 2020, 5:17 am EST

    Hello Ruchir,

    As I said our problem still exists in our application spread sheet.
    In case of exported sheet it works fine in most scenarios but we still see the inconsistent gap between the cell text and cell height.
    I wanted to know whether you could replicate our issue at your end, if so, what are the findings.
    We are using Spread.Net version 12.

    Thanks,
    Krishna
  • Replied 28 July 2020, 8:34 pm EST

    Hello Krishna,

    Using the AutoFit method, as suggested earlier we are not able to replicate the issue at our end even with Spread.Net 12. See attached image.
    For the same reason, I in my previous mentioned that the behavior is specific to your application and requested the code/stripped down application in order to investigate further.

    Thanks,
  • Replied 27 July 2020, 4:48 pm EST

    Hi Ruchir,

    Can you please post the attachment again as its not available for me.

    Thanks,
    Krishna
  • Replied 28 July 2020, 8:33 pm EST

    Hi Krishna,

    Please find attached screenshot to the output at my end, after using the AutoFit method and Spread.NET 12 version.
    Therefore, to proceed further I would request you to please share a stripped down demonstrating the issue.

    Regards,
  • Replied 23 August 2020, 4:46 pm EST

    Hi Ruchir,
    I understand how you are trying to replicate the issue. In the image attached, you are using a cell which contains single column.
    But the issue I mentioned is when you merge 2 or more columns and apply wordwrap to the text.
    However, I tried replicating the issue in grapecity spread sheet application but in this application, the wordwrap does not function if the columns are merged.
    I want to use a macro to apply GetPreferredHeight() to the cells when they are merged across the columns and check the row size of the cells. Please provide assistance in applying macros in spreadsheet.

    I want you to replicate the issue by merging across the columns and also by using GetPreferredHeight().

    Please help us in moving forward with this issue.
  • Replied 25 August 2020, 6:12 am EST

    Hi,

    It would not be possible to write VBA macros in Spread, however you can write custom functions. Please refer to the following link that information:https://www.grapecity.com/spreadnet/docs/v13/online-win/spwin-formulacustomfunc.html
    These are like macros you can use them in the SpreadSheet.

    Hope it will help you.

    Thanks,

  • Replied 21 September 2020, 6:50 pm EST

    Hi Ruchir,
    Please try to reproduce the issue by using single row and merging multiple columns.
    Attaching the image hoping that you will reproduce the same way.
    And to set wordwrap , we are using GetPreferredHeight(). Hence, I want you to use the same method for the exact results.
  • Replied 22 September 2020, 7:15 pm EST

    Hello,

    Before proceeding, I want to be sure that I am correctly comprehending the issue correctly. From the images you shared, I comprehend that the padding between cell content and cell borders in the second image is not the same as that in first image. For the multiline text (row#5), the padding/gap between content and border have decreased (in the bottom portion) and is no more similar to that of the single line text. Is this the issue you are reporting, right?

    To get the same layout, I have used the settings as shown in image below.
    Also, I have ensured that the LegacyBehavior is set to None and the version being used is Spread v12.


    Now, if I run the application, I do not see the same output as yours, that is, I cannot replicate the issue at my end using the code shown above. At my end, the padding remains same even after invoking the GetPreferredRowHeight method, for both, the single line text & multiline text. See attached video.


    So, can you kindly modify the attached application and share back with me, to make the application behave same as yours?
    Spread_Win.zip

    Thanks & Regards,
  • Replied 24 September 2020, 7:12 pm EST

    Hi Ruchir,
    Thanks for the sample application, it helped a lot.
    Made changes to the code and now I can see the issue replicated.
    Attaching the zip fie.
    Please help us in solving the problem.
  • Replied 24 September 2020, 10:47 pm EST

    Sorry, I couldn't attach the zip file because the size is larger. Can you provide me any other link for posting that?

    Regards,
    Krishna
  • Replied 27 September 2020, 2:51 pm EST

    Hi Krishna,

    Please use the following link: https://www.dropbox.com/request/MxUugVdWysFwli2OqemP

    Regards,
  • Replied 29 September 2020, 5:08 pm EST

    Hi Ruchir,
    I have placed the project in the given link.

    Regards,
    Krishna
  • Replied 30 September 2020, 3:01 am EST

    Hello Krishna,

    Thank you for the application. I can observe your concern.

    When the Row.GetPreferredHeight() method is called, the height of row is maximum of height of all RowHeader's cells and SheetView's cells. In this case the Rowheader's cell will have more height [24] than the normal cells [19]. So in the code, set the general cellType for sheetview' cells result will be 24. In the logic GetPreferredHeight of RowHeader's cell, the height is extended after measure the height of content, it's a old logic.

    Therefore, to resolve the problem for you, you need to use the GetPreferredRowHeight method and set the ignoreHeaders parameter to true, as follows:
    Cell controlCell = fpSpread1.ActiveSheet.Cells[2, 0];
    float heightFixed = fpSpread1.ActiveSheet.GetPreferredRowHeight(controlCell.Row.Index, true);
    fpSpread1.ActiveSheet.Rows[2].Height = heightFixed;

    Cell controlCell2 = fpSpread1.ActiveSheet.Cells[4, 0];
    float height2Fixed = fpSpread1.ActiveSheet.GetPreferredRowHeight(controlCell2.Row.Index, true);
    fpSpread1.ActiveSheet.Rows[4].Height = height2Fixed;
    Thanks,
    Ruchir
  • Replied 1 October 2020, 12:08 am EST

    Thanks Ruchir,
    I will try changing the parameters to the method and let you know how that worked in our application.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels