Home

Bytescout.XLS for .NET

Click to view full size screenshot

Bytescout.XLS library for .NET

Download Free Trial Buy Now More Information

How to enable Shrink To Fit property for cells so Excel will automatically fit text for the cell according to changed cell width in spreadsheet XLS document made with Bytescout.XLS library

This source code sample demonstrates how to use Shrink To Fit property for cell in spreadsheet generated with Bytescout.XLS library so generated XLS document will automatically fit text in the cell when opened in Excel 2003 or 2007

Download example source code: bytescoutxls_using_shrink_to_fit_for_cells.zip (10 KB)

Output XLS document screenshot (in Office 2003):

source Excel document with data table

Output XLS document screenshot (in Office 2007):
source Excel document with data table

Modified document screenshot (see Homer's Full Name changed)

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Bytescout.XLS;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Create new XLSDocument
XLSDocument document = new XLSDocument();

// Add new worksheet
Worksheet worksheet = document.WorkBook.Worksheets.Add("HelloWorld");

// Set cell value
worksheet.Cell(0, 0).Value = "Very, very, very, very long text";

// Shrink text
worksheet.Cell(0, 0).ShrinkToFit = true;

// Save document
document.SaveAs("CellShrinkToFit.xls");

// Close document
document.Close();

// open generated XLS document in default program
Process.Start("CellShrinkToFit.xls");
}
}
}

Download example source code: bytescoutxls_using_shrink_to_fit_for_cells.zip (10 KB)

Download Free Trial Buy Now More Information

First steps tutorials:

Advanced Examples:
Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement