Results 1 to 8 of 8

Thread: [WORD] Align To Decimal

  1. #1

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    [WORD] Align To Decimal

    I'm printing out huge tables of numbers aligned to the centre of each cell.
    This looks fine except when negative numbers start to appear.
    The align to centre then doesn't look quite right as the negative sign casues a bit of offset.

    The way around this is to align to the decimal point by putting a decimal tab in the middle of the cell and aligning left to it.

    However, I am currently only doing this by eye.
    How can I work out programatically where to put the decimal tab, based on the length of the number?

    The numbers will all have the same number of decimal places in each column but can have different number of places in different columns/tables.

  2. #2

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: [WORD] Align To Decimal

    I bit more digging and I think I might have to use something like
    VB Code:
    1. Selection.Rows.SpaceBetweenColumns
    2. Selection.Information(wdHorizontalPositionRelativeToPage)
    3. Selection.Information(wdHorizontalPositionRelativeToTextBoundary)

    I can't fully work it out though, I think it might have something to do with returning different types of measurement points/twips/cm/in etc

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [WORD] Align To Decimal

    So you want all numbers aligned center with the deimal points? Can you post a sample?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: [WORD] Align To Decimal

    Table 1 is centred.
    Table 2 is aligned to decimal.

    This is just doing it by eye.
    Attached Files Attached Files

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [WORD] Align To Decimal

    Its being aligned correctly by the PIMMS + Left font?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: [WORD] Align To Decimal

    I forgot that the style was still applied.
    The first table is aligned by the Style (Normal + Centred)

    The second table still has the Style applied but I have put Decimal tabs over each column and aligned to the left.

    The net result is that the columns are aligned to the centre (or near enough) and all the decimal points line up.

    I am running Word 2000.
    If you are running Word XP it will probably give a slight change to the description of the style in the second table.

    The important thing is the decimal tab.
    You can add them by either double clicking in the horizontal ruler and selecting decimal Tab then typing the position you want.
    Or you can click the tab icon (to the left of the horizontal ruler) several times until it looks like an inverted 'T' with a dot on the right.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [WORD] Align To Decimal

    You can set a decimal tab via code like so.
    VB Code:
    1. Selection.ParagraphFormat.TabStops(InchesToPoints(0.35)).Position = InchesToPoints(0.35)
    2.     Selection.ParagraphFormat.TabStops.ClearAll
    3.     ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
    4.     Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(0.35), Alignment:=wdAlignTabDecimal, Leader:=wdTabLeaderSpaces
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: [WORD] Align To Decimal

    The complicated bit is knowing where to put the decimal tab though.
    The tabs would be in different positions depending upon the number of decimal places in the column.
    I suppose I could manually work it out then have a lookup table, but calculating it seems better.
    Psuedo code of what I am trying to do
    Code:
    A = Column Width
    B = String Width
    Tab position = (A / 2) - (B / 2)
    Although the tab wouldnt be exactly in this position due to the decimal place being after the negative sign and the first 0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width