none
Bulleted List within a Table RRS feed

  • Question

  • Hi All

     

    I'm trying to programatically create a bulleted list and the place that within a Table Cell

    Currently, I'm creating text in the form of

    1.  Question ...

        (this is the part that needs to be a bullet list)

        a)  option 1

        b)  option 2

        c)  option 3

        d)  option 4

    2)  Question ...

     

    This is for a test form.

     

    Also, is there anyway to control the line spacing?  I have it set to Single, but there is still too much space between the lines.

     

    Thanks All

    D

    Wednesday, December 14, 2011 4:33 PM

Answers

  • Hi Dorris

    Thanks for confirming we're thinking more or less about the same thing, and the version information. Are you familiar with Word STYLES? The most stable and simplest way to approach this would be:

    1. Create a paragraph style for the Q, and another for the options

    2. Create a list style (numbering style) for both levels. Set the top level for no number (your code will write the number) and the second level for a), b), etc. with the indent. Link each of these levels to the corresponding paragraph style.

    When you apply the paragraph style to the range, the corresponding number format will automatically be applied and, by default, will restart the numbering when the first level numbering intervenes (which is why you want that top level, even if it doesn't apply a number).

    Since all of this is going to be done with your code (unless you have the option of creating these documents from a prepared template), practice creating the paragraph styles and list templates until they meet your satisfaction and you can perform the steps in one pass.

    Start Word's macro recorder and record defining the paragraph and list styles. That will give you the basic syntax for your code.

    You'll notice that Word generates nine levels for the list style. This is correct and, if the user doesn't start "getting fancy" it won't matter. If there's a danger that the user will start applying other list levels, give them either a neutral format (like the general text) or a "Warning" format (link them with a bright red paragraph style and a warning message instead of a number format, for example).


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Monday, December 26, 2011 6:34 AM
    • Marked as answer by Bruce Song Wednesday, January 4, 2012 7:43 AM
    Thursday, December 15, 2011 1:26 PM
    Moderator

All replies

  • Hi D

    Numbering is a complex topic, so it would help to know a bit more about your project before we start playing with code...

    Which version of Word is this?

    Can you show us how you're currently populating the table?

    Are you familiar with the concept of paragraph styles? How about list styles and templates?

    Are you creating this content in a prepared document or template, or having to do this with "any old document"? (I ask because it's important to know how much of this can be predefined and how much your code has to do.)

    Do you really mean "bullets", as in the text of your problem description, or do you mean a, b, c, d, as you show in your example?


    Cindy Meister, VSTO/Word MVP
    Wednesday, December 14, 2011 4:56 PM
    Moderator
  • Hello,

     

    Acces the range of the cell, and apply

     cellRange.ParagraphFormat.LineSpacing = 50;
    


    This will give you indent on the text in that range. Try using number bigger than the font size(50 is a good spacing). Also the number must be smaller than 1785, try it yourself.

     

    Best regards,

    Silviu.

     


    http://www.rosoftlab.net/
    Wednesday, December 14, 2011 4:58 PM
  • Cindy

     

    This is a (currently) Visual Foxpro application that creates an 100 question test form and then (this is the part I'm trying to do) open a Word doc and 'print' the form.  There are plans for future (how future no one seems to know) conversion to .Net.

    I'm doing this by opening Word (CreateObject("Word.exe"), doing a Document.Add() and going from there.

    I place some header information in the Document Header and create a Footer for page numbers.  I then create a Table for the body of the document.  The text is created out of fields in a VFP table by building a string of the form:

    QuestionText + CR + Option1 + CR + Option2 + CR + Option3 +CR + Option4.  This string is then placed in the table cell.

    If you need more information, please ask.

     

    Dorris

    And I want the a, b, c, d showing as 'bullets' for the indentation of any continuation line.

    Wednesday, December 14, 2011 5:36 PM
  • Hi Dorris

    <<And I want the a, b, c, d showing as 'bullets' for the indentation of any continuation line.>>

    Sorry to be a pest, but I'm still not clear whether you want to see "a, b, c, d", literally, or whether you want to see bullet symbols. This makes a huge difference, which is why I'm so insistent :-)

    and I think we're going to have to get accustomed to each other's "syntax". Word has some very specific terms and I tend to think literally when these are used.

    I'm going to try describing what you want in my own words and please double-check me on this:

    You want to "drop" the string of Q&A into each table cell, then format it with the outline numbering (one level for the question, next level for the options). The numbering of level 1 will increment from table cell to table cell.

    I'd like you to try something out in Word, as an end-user, to make sure we're on the same wavelength. Put some text into a Word document to represent two or three Q & A sections (similar to your original post). You still haven't told me which version of Word this is (and yes, it makes a tremendous difference), so I'm going to assume 2007.

    Select all the text. Go to Home/Paragraph and click on the dropdown arrow next of the "multilevel list" button. Choose the item that comes closest to the numbering you want (1)a), for example). At this point, all lines should be numbered from 1 to n. Go to a line that should be the next level and press Shift + Alt + Right Arrow. This should apply a) then b), etc.

    Is this basically what you're looking for? And does this give you a feel for how Word's numbering works - at a very, very basic level?

    I'm just getting ready to shut down for the night, so you won't see any answers from me until tomorrow (if nothing gets in the way of my being on-line, such as the power outage we had today).


    Cindy Meister, VSTO/Word MVP
    Wednesday, December 14, 2011 5:57 PM
    Moderator
  • Cindy

     

    Sorry, yes this is Word 2007, and yes - you've 'translated' what I'm wanting correctly.  I'm not sure that the top level numbering (1, 2, 3, etc) will work for me since it has to be printed in from top to bottom and in two columns so that the left hand column is numbered, for example, 1 through 5 and the right hand column is numbered 6 through 10 and the the left hand column on page 2 starts with number 11 and so forth. I can get the Question level numbering - it's the sublist that's the issue.

     

    Dorris

     

    Wednesday, December 14, 2011 6:58 PM
  • Hi Dorris

    Thanks for confirming we're thinking more or less about the same thing, and the version information. Are you familiar with Word STYLES? The most stable and simplest way to approach this would be:

    1. Create a paragraph style for the Q, and another for the options

    2. Create a list style (numbering style) for both levels. Set the top level for no number (your code will write the number) and the second level for a), b), etc. with the indent. Link each of these levels to the corresponding paragraph style.

    When you apply the paragraph style to the range, the corresponding number format will automatically be applied and, by default, will restart the numbering when the first level numbering intervenes (which is why you want that top level, even if it doesn't apply a number).

    Since all of this is going to be done with your code (unless you have the option of creating these documents from a prepared template), practice creating the paragraph styles and list templates until they meet your satisfaction and you can perform the steps in one pass.

    Start Word's macro recorder and record defining the paragraph and list styles. That will give you the basic syntax for your code.

    You'll notice that Word generates nine levels for the list style. This is correct and, if the user doesn't start "getting fancy" it won't matter. If there's a danger that the user will start applying other list levels, give them either a neutral format (like the general text) or a "Warning" format (link them with a bright red paragraph style and a warning message instead of a number format, for example).


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Monday, December 26, 2011 6:34 AM
    • Marked as answer by Bruce Song Wednesday, January 4, 2012 7:43 AM
    Thursday, December 15, 2011 1:26 PM
    Moderator
  • Thanks Cindy,

     

    I'll give this a try - though I'm not sure if Word will be allowed to run/record macros, I know for Excel they've been disabled at a System Level.

     

    Dorris

    Thursday, December 15, 2011 2:06 PM
  • I'll give this a try - though I'm not sure if Word will be allowed to run/record macros, I know for Excel they've been disabled at a System Level.


    Let's hope you can at least find a lap-top somewhere... That makes things so much easier for this as there are so many properties and parameters. If you try to do it from scratch it's just plain painful.

    If not, I think you'll find a code example or two in this and/or the VSTO forum. It won't be exactly what you need, but at least it will give you the basic syntax with all the parameters, etc.


    Cindy Meister, VSTO/Word MVP
    Thursday, December 15, 2011 2:21 PM
    Moderator