PC Review


Reply
Thread Tools Rate Thread

Centreing Text In Excel Cells

 
 
Alan
Guest
Posts: n/a
 
      22nd Apr 2010
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.
--
Alan M
 
Reply With Quote
 
 
 
 
Duke Carey
Guest
Posts: n/a
 
      22nd Apr 2010
Alan -

Maybe

xlSheet.Range("A:L").HorizontalAlignment = xlCenter


"Alan" wrote:

> 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.
> --
> Alan M

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to add text to all cells in excel or merge the text in two ce Juan Maldonado Microsoft Excel Misc 1 8th Sep 2009 03:11 AM
Excel Changes Text Cells to Number Cells When Importing XML Villerat Microsoft Excel Misc 0 24th Jul 2008 01:59 AM
3D Text in Excel cells =?Utf-8?B?QmlsbE0=?= Microsoft Excel Misc 4 1st Feb 2007 02:18 PM
In Excel, option to enter text in cells the same as text boxes =?Utf-8?B?Um9iR01V?= Microsoft Excel Worksheet Functions 0 26th Oct 2005 04:20 PM
Cells with same text but excel think it's different? =?Utf-8?B?SmFzb24=?= Microsoft Excel Misc 4 6th Aug 2004 12:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:16 PM.