Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. excel cell alignment

excel cell alignment

Scheduled Pinned Locked Moved C#
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michael_jhons
    wrote on last edited by
    #1

    hello everybody can somebody help me in formating excel cells inside a worksheet: i tried

    worksheet.get_Range(worksheet.Cells[2, 1], worksheet.Cells[2, 3]).HorizontalAlignment = HorizontalAlignment.Left;

    but gave me an error i made a research i found that i have to use

    ... HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

    the problem is that i couldn't find XlHAlign property i tried many reference but without any solution. thank you in advance and kind regards

    P M 2 Replies Last reply
    0
    • M michael_jhons

      hello everybody can somebody help me in formating excel cells inside a worksheet: i tried

      worksheet.get_Range(worksheet.Cells[2, 1], worksheet.Cells[2, 3]).HorizontalAlignment = HorizontalAlignment.Left;

      but gave me an error i made a research i found that i have to use

      ... HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

      the problem is that i couldn't find XlHAlign property i tried many reference but without any solution. thank you in advance and kind regards

      P Offline
      P Offline
      Pedram Behroozi
      wrote on last edited by
      #2

      michael_jhons wrote:

      but gave me an error i made a research i found that i have to use ... HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

      But it worked for me! :confused: It's my code:

      using System;
      using System.Text;
      using Microsoft.Office.Interop.Excel;

      namespace ConsoleApplication2
      {
      class Program
      {
      static void Main(string[] args)
      {
      WorksheetClass ws = new WorksheetClass();
      ws.get_Range(ws.Cells[2, 1], ws.Cells[2, 3]).HorizontalAlignment = XlHAlign.xlHAlignCenter;
      }
      }
      }

      While (true) { Human.isLearnable = true; }

      M 1 Reply Last reply
      0
      • P Pedram Behroozi

        michael_jhons wrote:

        but gave me an error i made a research i found that i have to use ... HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

        But it worked for me! :confused: It's my code:

        using System;
        using System.Text;
        using Microsoft.Office.Interop.Excel;

        namespace ConsoleApplication2
        {
        class Program
        {
        static void Main(string[] args)
        {
        WorksheetClass ws = new WorksheetClass();
        ws.get_Range(ws.Cells[2, 1], ws.Cells[2, 3]).HorizontalAlignment = XlHAlign.xlHAlignCenter;
        }
        }
        }

        While (true) { Human.isLearnable = true; }

        M Offline
        M Offline
        michael_jhons
        wrote on last edited by
        #3

        thank you pedram, it was the

        using Microsoft.Office.Interop.Excel;

        i added as a reference but when i added from using XLHalign apears, thank you fro your help

        1 Reply Last reply
        0
        • M michael_jhons

          hello everybody can somebody help me in formating excel cells inside a worksheet: i tried

          worksheet.get_Range(worksheet.Cells[2, 1], worksheet.Cells[2, 3]).HorizontalAlignment = HorizontalAlignment.Left;

          but gave me an error i made a research i found that i have to use

          ... HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter

          the problem is that i couldn't find XlHAlign property i tried many reference but without any solution. thank you in advance and kind regards

          M Offline
          M Offline
          minhlao
          wrote on last edited by
          #4

          Range rng = objSheet.getRange(col1, row1,col2 ,row2); rng.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ;) enjoy it soicodon : mihazu_undead@yahoo.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups