Centreing Text In Excel Cells

A

Alan

I am send data to an Excel Spreadsheet, which includes some numeric data and
some text data.

I want to have the text in all columns in the centre of the cell. I have
tried lots of different code:-

xlSheet.Range("A:L").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells.HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Columns.HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells(10, 1).HorizontalAlignment = HorizontalAlignment.Left
xlSheet.Columns("C").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Range("A6:L15").HorizontalAlignment = HorizontalAlignment.Center
xlSheet.Cells.HorizontalAlignment = True
xlSheet.Range("A6:L15").HorizontalAlignment = HorizontalAlignment.Center

but nothing seems to work.

If I use horizontalalignment.left the code will not work and I get error
reports.
If I use horizontalalignment.right all the cells requested are aligned to
the left.
If I use horizontalalignment.center the cells are as you would see in a
spreadsheet,
numeric on the right and text on the left of the cell.

All other forms of formatting, i.e. Font.Size, Font.Bold, BorderAround all
work.
The data is being sent to Excel 2000, may seem a bit archaic but it is only
being used to give a direct printout of the data, easier than formatting it
into a document.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top