worksheet.column.Autofit()

Posted by: srg13 on 8 June 2023, 1:33 am EST

  • Posted 8 June 2023, 1:33 am EST - Updated 8 June 2023, 1:38 am EST

    Hi,

    I am creating a worksheet where the requirement is to autofit the columns. I have used the autofit statement on the entire spreadsheet but I am not getting the desired output. can you please help me with this? I am attaching screenshots of current output and expected output.

    Iam using worksheet.Columns.AutoFit() before saving the excel.

  • Posted 8 June 2023, 5:08 pm EST - Updated 8 June 2023, 5:13 pm EST

    Hi,

    We are unable to replicate this issue at our end i.e., AutoFit method for Columns is working as expected.

    Please refer the attached gif:

    Please refer the sample for the same: AutoFitSample.zip

    Could you please provide a small stripped sample replicating this behavior? So, that we can investigate further and assist you accordingly.

    Best Regards,

    Nitin

  • Posted 9 June 2023, 11:26 pm EST

    Thanks Nitin for the reply. I was able to get it working the way you have showed. But the requirement is to show as i have attached in my second screenshot.

    I am working on a project to generate excel using grapecity. This excel was earlier created through a macro and my stakeholders want to have the same look and feel . so is there a way i can achieve column fit as in my second screenshot? Any addition settings/configs that can help?

  • Posted 11 June 2023, 8:56 pm EST

    Hi,

    To achieve this requirement, you need to Autofit columns for the required range.(see code snippet)

    worksheet.Range["A2:F21"].Columns.AutoFit();

    Please refer the attached sample for the same: AutoFitSample_Mod.zip

    Best Regards,

    Nitin

Need extra support?

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

Learn More

Forum Channels