开发者

Changing Bullet Styles with Word 2007 Automation in C#

I am trying to change the style of my bullets in a word document (Word 2007).... I currently place a bullet and it comes out as a circle. I want it to be a square... here's my code for applying bullets...

    public void ToggleBullets(bool bulletsOn)
{
    Microsoft.Office.Interop.Word.Application wd;
    Object _oMissing = Type.Missing;
    Object _numberType = WdNumberType.wdNumberListNum;
    if (bulletsOn)
    {
        wd.Selection.Range.ListFormat.ApplyBulletDefault(ref _oMissing);
    }
    else
    {
        wd.Selection.Range.ListFormat.RemoveNumbers(ref _numberType);
    }
}

any ideas? Let me kn开发者_如何学JAVAow if you need more details


I use the Open XML SDK 2.0 Productivity Tool for Microsoft Office: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&displaylang=en

When I want to to do these kinds of things. Just launch the Productivity tool, load up the .docx that has what you want and then let the tool generate the code for you.

I just whipped up an example and this was the code it generated:

using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
....
    public Paragraph GenerateParagraph()
    {
        Paragraph paragraph1 = new Paragraph(){ RsidParagraphAddition = "00EA7FFB", RsidParagraphProperties = "00EA7FFB", RsidRunAdditionDefault = "00EA7FFB" };

        ParagraphProperties paragraphProperties1 = new ParagraphProperties();
        ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId(){ Val = "ListParagraph" };

        NumberingProperties numberingProperties1 = new NumberingProperties();
        NumberingLevelReference numberingLevelReference1 = new NumberingLevelReference(){ Val = 0 };
        NumberingId numberingId1 = new NumberingId(){ Val = 2 };

        numberingProperties1.Append(numberingLevelReference1);
        numberingProperties1.Append(numberingId1);

        paragraphProperties1.Append(paragraphStyleId1);
        paragraphProperties1.Append(numberingProperties1);

        Run run1 = new Run();
        Text text1 = new Text(){ Space = SpaceProcessingModeValues.Preserve };
        text1.Text = "Item ";

        run1.Append(text1);

        paragraph1.Append(paragraphProperties1);
        paragraph1.Append(run1);
        return paragraph1;
    }

This is using the OpenXml headers, and not Word specifically

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜