开发者

Which WdBreakType constants are universally safe to use in range.InsertBreak?

I am writing a C# WinForms program using the Word 2003 PIA which gives users the capability to insert different sorts of breaks. I am using the range.InsertBreak method which takes a WdBreakType argument.

Looking at the Microsoft Documentation for the range.InsertBreak method, I noticed the following statement:

"Some of the WdBreakType constants may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed."

I was wondering if there are any members of the enumeration that I should avoid using. I have not been able to find any documentation on the subject.

public enum WdBreakType
{
    wdSectionBreakNextPage = 2,
    wdSectionBreakContinuous = 3,
    wdSectionBreakEvenPage = 4,
    开发者_开发百科wdSectionBreakOddPage = 5,
    wdLineBreak = 6,
    wdPageBreak = 7,
    wdColumnBreak = 8,
    wdLineBreakClearLeft = 9,
    wdLineBreakClearRight = 10,
    wdTextWrappingBreak = 11,
}


I haven't been able to find anything either, but two ideas strike me;

1) The reference to culture suggests that the problems occur when designing documents that use a very different layout style from regular British or US documents; say, Arabic documents flowing right-to-left. This may change the meaning of, say wdLineBreakClearLeft. If you intend to produce only familiar left-to-right documents in your app, you may not need to worry about this aspect at all.

2) Since it is the Range object's documentation that mentions the limits, it makes me think that there are certain breaks which are not appropriate in certain ranges. For example, a page break is probably only appropriate in the main story, not in a header.

You can check the range's story type like so;

if (range.StoryType == WdStoryType.wdMainTextStory)
{

}

I guess you could write a quick app to test what types can be used in what types of stories;

//! Scrappy Code;    
var breakTypes = new [] { WdBreakType.wdColumnBreak, WdBreakType.wdLineBreak };
foreach(var breakType in breakTypes)
{
    foreach(var storyRange in wordDoc.StoryRanges)
    {
        try
        {
            storyRange.InsertBreak(breakType);
            Console.WriteLine("Can insert {0} into {1}", breakType, storyRange.StoryType)
        }
        catch(Expection ex)
        {
            Console.WriteLine("Cannot insert {0} into {1}: {2}", breakType, storyRange.StoryType, ex.Message)
        }
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜