none
how can i use exactly built-in style in document? RRS feed

  • Question

  • i have a very simple document, which looks like below picture:

    the heading style is different between built-in styles:

    so i using below code to delete non-built-in style:

    Word.Styles styles = doc.Styles;
    foreach (Word.Style style in styles) {
    	if (!style.BuiltIn)
    		style.Delete();
    }

    but all of the style's builtIn property is true, so does not delete any styles.

    anyone can tell me the reason?they look like so differently, i want to use the style in picture2. how can i do it?


    • Edited by sendreams Thursday, March 20, 2014 10:50 AM
    Thursday, March 20, 2014 10:42 AM

Answers

  • Hi,

    >>how can i set all style(in picture1) back to the exactly built-in styles(in picture2)?<<

    In fact, we could modify the property of all styles or rename them no matter they are built-in or not. So I think all styles in picture1 are modified with their name or other properties. But I'm afraid there is no property or method of Style Object to reset the name back as the picture 2 in Word Object Model currently. You may need to modify it back manually.

    By the way, you could also consider posting it in Word IT pro Forum for more effective responses.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 21, 2014 12:00 PM
    Moderator

All replies


  • i use the code to get the heading's style:

    Word.Style style = p.get_Style();
    Debug.WriteLine(style.NameLocal);

    the value of NameLocal property is very complex:

    Heading 1,&3,1,1st level,Datasheet title,H1,H11,H12,H13,H14,H15,H16,H17,Head 1,Head 11,Head 111,Head 12,Head1,Header1,Heading 0,Heading apps,L1,Level 1 Topic Heading,List level 1,PIM 1,SAHeading 1,Section Head,boc,h1,l1,卷标题,合同标题,标书1,标题 1 1,标题一,章,章节标题
    
    
    Heading 2,2,H2,H21,H211,H212,H22,H23,HD2,Head 2,Heading 2 CCBS,Heading 2 Hidden,ISO1,PIM2,Titre3,UNDERRUBRIK 1-2,Underrubrik1,h2,heading 2,heading 2TOC,l2,list 2,list 2,prop2,sect 1.2,sect 1.21,sect 1.211,sect 1.212,sect 1.22,sect 1.23,子,子系统,第一章 标题 2


    how can i delete these style which maybe inherit from built-in style.

    Thursday, March 20, 2014 11:13 AM
  • Hi,

    In fact, Style.BuiltIn Property is True if the specified object is one of the built-in styles or caption labels in Word. When the style is a custom one, style.BuiltIn will return false. So with the code above, it will delete all custom styles. If there is no custom styles in your Word application, it won't delete any one.

    If you want to set the style of a paragraph, here is a sample for your reference.

    doc.Paragraphs[1].set_Style(doc.Styles["Heading 1"]);

    More details, please refer to Style Object.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 21, 2014 11:32 AM
    Moderator
  • hi, Luna

    thank you for your reply

    i know how to set the heading style, i just did not understand why all these style are built-in but has so different presentation.

    how can i set all style(in picture1) back to the exactly built-in styles(in picture2)?

    Friday, March 21, 2014 11:49 AM
  • Hi,

    >>how can i set all style(in picture1) back to the exactly built-in styles(in picture2)?<<

    In fact, we could modify the property of all styles or rename them no matter they are built-in or not. So I think all styles in picture1 are modified with their name or other properties. But I'm afraid there is no property or method of Style Object to reset the name back as the picture 2 in Word Object Model currently. You may need to modify it back manually.

    By the way, you could also consider posting it in Word IT pro Forum for more effective responses.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 21, 2014 12:00 PM
    Moderator
  • hi, Luna

    thank you very much.

    if can not modify by api, is any way do a totally reset?

    Friday, March 21, 2014 12:35 PM
  • Hi,

    >>if can not modify by api, is any way do a totally reset?<<

    As far as I know, No.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, March 23, 2014 5:21 AM
    Moderator