We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Access to characterstyle

Thread ID:

Created:

Updated:

Platform:

Replies:

79610 Feb 17,2009 08:16 AM Feb 25,2009 03:55 AM Windows Forms 8
loading
Tags: DocIO
Pierre CHAUSSEE
Asked On February 17, 2009 08:16 AM

Hi,

I'm trying to identify whether a WTextRange is in bold characters.
I can not identify it when those characters are bold because of a word character style.
When i use quickwatch to watch my WTextRange, I see that Bold is set to false but its CharacterStyle.CharacterStyleName refers to a CharacterStyle which is in Bold.

My problem is that CharacterStyle class and CharacterStyleName properties are 'Friend', therefore I can not access them through code.

Can you help me to find how can I get CharacterStyle informations ?

In advance, thank you


Bhuvaneswari P [Syncfusion]
Replied On February 18, 2009 05:21 AM

Hi Pierre,

Thank you for your interest in Syncfusion products.

It is possible to access the WTextRange characterStyle information by using the CharacterFormat object. Please refers to the below code snippet to access the WTextRange characterFormat.

//Assign to characterFormat class and get the class information
TextRange range = item as WTextRange;
WCharacterFormat characterformat = range.CharacterFormat;
MessageBox.Show(characterformat.Bold.ToString());

//Direct access
MessageBox.Show(range.CharacterFormat.Bold.ToString ());

In DocIO everything is Section, Paragraph based. So you can access and check the text character by enumerating each section, paragraph and its item. Please use the below code snippet to do so:


WordDocument document = new WordDocument(@"..\..\charstyle.doc");
foreach (Entity ent in document.ChildEntities)
{
if (ent is WSection)
{
WSection section = ent as WSection;
foreach (WParagraph paragraph in section.Body.Paragraphs)
{
foreach (ParagraphItem item in paragraph.Items)
{
if (item.EntityType == EntityType.TextRange)
{
WTextRange range = item as WTextRange;
WCharacterFormat characterformat = range.CharacterFormat;
MessageBox.Show(characterformat.Bold.ToString());

MessageBox.Show(range.CharacterFormat.Bold.ToString ());

}
}
}
}
}


Please try this and let us know if this helps you.

Best Regards,
Bhuvana



Pierre CHAUSSEE
Replied On February 18, 2009 06:11 AM

Hi Bhuvana,
And thank you for your answer.

The thing is that Bold property does not show if my textrange is really in bold characters.
For example if in your Word document you ahve specified a Paragraph Style in Bold. The Bold property of the text range is set to false.

That means you have to check both paragraph Style.CharacterFormat.Bold and WTextRange.CharacterFormat.Bold property.

The problem is that in my case I do not have a paragraph style defined in Word but a CharacterStyle. And I can't see how to access that character style.

You'll see in the attachment a word document with a character style defined. You'll notice that when I read it with DocIO that both
Paragraph Style.Bold and WTextRange.Bold are set to false.

How can I access the CharacterStyle since that class is friend in DocIO ?



>Hi Pierre,

Thank you for your interest in Syncfusion products.

It is possible to access the WTextRange characterStyle information by using the CharacterFormat object. Please refers to the below code snippet to access the WTextRange characterFormat.

//Assign to characterFormat class and get the class information
TextRange range = item as WTextRange;
WCharacterFormat characterformat = range.CharacterFormat;
MessageBox.Show(characterformat.Bold.ToString());

//Direct access
MessageBox.Show(range.CharacterFormat.Bold.ToString ());

In DocIO everything is Section, Paragraph based. So you can access and check the text character by enumerating each section, paragraph and its item. Please use the below code snippet to do so:


WordDocument document = new WordDocument(@"..\..\charstyle.doc");
foreach (Entity ent in document.ChildEntities)
{
if (ent is WSection)
{
WSection section = ent as WSection;
foreach (WParagraph paragraph in section.Body.Paragraphs)
{
foreach (ParagraphItem item in paragraph.Items)
{
if (item.EntityType == EntityType.TextRange)
{
WTextRange range = item as WTextRange;
WCharacterFormat characterformat = range.CharacterFormat;
MessageBox.Show(characterformat.Bold.ToString());

MessageBox.Show(range.CharacterFormat.Bold.ToString ());

}
}
}
}
}


Please try this and let us know if this helps you.

Best Regards,
Bhuvana





Bhuvaneswari P [Syncfusion]
Replied On February 19, 2009 09:18 AM

Hi Pierre,

Thanks for the update.

I am working on this issue and update the details by tomorrow.

Best Regards
Bhuvana


Bhuvaneswari P [Syncfusion]
Replied On February 20, 2009 05:40 AM

Hi Pierre,

Thanks for the details and I couldn't find any attachment in your last update.

Accessing the CharacterStyle can be possible by getting the document styles list by using the document.Styles property and we can check corresponding type. I am afraid that I am unable to reproduce the issue while accessing through document.Styles and using WtTextRnage CharacterFormat, it returning the correct value for Bold property. Please refers to the below code to access the format through styles.


IStyleCollection col = document.Styles;
foreach (Style st in col)
{
if (st.StyleType == StyleType.CharacterStyle)
{
WCharacterFormat ch = st.CharacterFormat;
//To change the style
//ch.TextBackgroundColor = Color.Red;
Console.WriteLine("Style Type = " + st.StyleType.ToString() + " Bold= " + ch.Bold.ToString() );
}
}

Here is the sample for both the methods:

http://www.syncfusion.com/uploads/redirect.aspx?file=Character_Style1_a40b4f6e.zip&team=support


Please have a look into the sample and could you please send us the modified one to reproduce the issue and to investigate further on this issue?

Best Regards,
Bhuvana


Pierre CHAUSSEE
Replied On February 20, 2009 10:45 AM

Hi Bhuvana,

Thanks for the answer, I'm surprised you get correct values with the word document I did provide you, since I don't but anyway thanks for the method that allows to browse document.Styles
The only thing is :
How do I know which Character Style is used on my WTextRange ?

>Hi Pierre,

Thanks for the details and I couldn't find any attachment in your last update.

Accessing the CharacterStyle can be possible by getting the document styles list by using the document.Styles property and we can check corresponding type. I am afraid that I am unable to reproduce the issue while accessing through document.Styles and using WtTextRnage CharacterFormat, it returning the correct value for Bold property. Please refers to the below code to access the format through styles.


IStyleCollection col = document.Styles;
foreach (Style st in col)
{
if (st.StyleType == StyleType.CharacterStyle)
{
WCharacterFormat ch = st.CharacterFormat;
//To change the style
//ch.TextBackgroundColor = Color.Red;
Console.WriteLine("Style Type = " + st.StyleType.ToString() + " Bold= " + ch.Bold.ToString() );
}
}

Here is the sample for both the methods:

http://www.syncfusion.com/uploads/redirect.aspx?file=Character_Style1_a40b4f6e.zip&team=support


Please have a look into the sample and could you please send us the modified one to reproduce the issue and to investigate further on this issue?

Best Regards,
Bhuvana




Bhuvaneswari P [Syncfusion]
Replied On February 24, 2009 05:33 AM

Hi Pierre,

Thanks for the update.

Currently we don't have any property to check the WTextRange character style; we can only check the characterformat used for that TextRange using the below code snippet:

WTextRange range = item as WTextRange;
WCharacterFormat characterformat = range.CharacterFormat;
Console.WriteLine("Text =" + range.Text);
Console.WriteLine("Bold= " + characterformat.Bold.ToString());


Please try this if it’s not return the correct character format then could please provide with your word document with code snippet to reproduce the issue. It would be helpful to analysis more on this issue.

Best Regards,
Bhuvana


Pierre CHAUSSEE
Replied On February 24, 2009 05:55 AM

Hi Bhuvana,

It doesn't work. Here's the document, I'm sorry you didn't receive in my older post, I just realised you didn't.

Thank you,
Pierre



Syncfusion_92816a17.zip

Bhuvaneswari P [Syncfusion]
Replied On February 25, 2009 03:55 AM

Hi Pierre,

Thanks for the document.

I am able to reproduce the issue when applying the customer character style to the text; it’s not returning the correct value. Could you please open a new direct – trac incident with subject line as Forum 79610 - Access to characterstyle? So that it would be possible for us to provide more details regarding this issue.

Best Regards,
Bhuvana



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;