VS 2003 C# -- writing to Excel

Posted on 2007-08-06
Last Modified: 2008-01-09
From C# (VS 2003) I am writing to an Excel Spreadsheet using techniques like this:

range.get_Offset(l,0).set_Value(Missing.Value,"Account Number");
range.get_Offset(l,1).set_Value(Missing.Value,"Management Group");
range.get_Offset(l,2).set_Value(Missing.Value,"Customer Type");
range.get_Offset(l,3).set_Value(Missing.Value,"Customer Date of Birth");
range.get_Offset(l,4).set_Value(Missing.Value,"Customer Name");


range.get_Offset(l,3).EntireColumn.NumberFormat = "MM/DD/YYYY";

The spreadsheet ends up with 63 columns.

Before saving, I would like to adjust the column width for each column to match the size of the data written to it.  If possible I would like to emulate the Excel process whereby you select all columns and double-click on a border to automatically adjust them.  If that's not possible, I would need to adjust each column manually.

How do I accomplish this?
Question by:g_johnson
    LVL 4

    Accepted Solution

    In VB you would use:

    LVL 4

    Author Comment


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Introduction This Article is a follow-up to my Mappit! Addin Article (, it was inspired by an email posting I made to EUSPRIG (, I will briefly cover: 1) An overvie…
    Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now