[]
        
(Showing Draft Content)

Shrink To Fit With Text Wrap

GcExcel .NET enables users to implement the shrink to fit feature in a cell along with the wrapped text. The Shrink to Fit feature automatically reduces the font size of the text so that it fits inside the cells of the spreadsheet without wrapping.

Advantage of Using Shrink To Fit Feature

The Shrink to Fit feature implemented with wrapped text is useful especially when you need to deal with spreadsheets possessing tightly constrained layouts with vertical spaces and wrapped text. Also, this feature can be used when users don't want to opt for Auto fit row height and column width option to adjust the column width and row height as per their preferred worksheet layout.

The following points should be kept in mind while working with the shrink to fit feature:

  • If you're exporting your Excel files to a pdf file or stream, the PdfSaveOptions class can be used to configure the save settings.

  • In order to get or set the settings about enabling the shrink to fit feature on the wrapped text, you can use the the ShrinkToFitSettings property of the PdfSaveOptions class.

  • The CanShrinkToFitWrappedText property of the IShrinkToFitSettings interface can be used to get or set whether to apply shrink to fit feature on the wrapped text. If the value is true, the font size of the wrapped text may be reduced so that the wrapped text can be fully displayed.

  • The MinimumFont property of the IShrinkToFitSettings interface can be used to get or set the minimum font size while enabling the shrink to fit feature.

  • The Ellipsis property of the IShrinkToFitSettings interface can be used to get or set the omitted string if the wrapped text is not fully displayed. This can be used with the MinimumFont property.

Using Code

Refer to the following example code to allow users to use the shrink to fit feature with text wrap.

// Initialize workbook
Workbook workbook = new Workbook();
        
// Fetch default worksheet 
IWorksheet worksheet = workbook.Worksheets[0];

// Configure page settings
worksheet.PageSetup.PrintGridlines = true;
worksheet.Range["A1"].RowHeightInPixel = 10;
worksheet.Range["A1"].ColumnWidthInPixel = 70;
worksheet.Range["A1"].WrapText = true;
worksheet.Range["A1"].ShrinkToFit = true;
worksheet.Range["A1"].Value = "GrapeCity Documents For Excel";

// Setting PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.ShrinkToFitSettings.CanShrinkToFitWrappedText = true;
pdfSaveOptions.ShrinkToFitSettings.MinimumFont = 12;
pdfSaveOptions.ShrinkToFitSettings.Ellipsis = "~";

// Saving the workbook to PDF
workbook.Save("ShrinkToFitWrappedText.pdf", pdfSaveOptions);