We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Small problem when changing Font properties

When I try to change properties for some of my text in Word all text in the document is changed.
Here is how my code looks.

cell = new Cell(doc);
Paragraph paragraph = new Paragraph(doc);
Font f = paragraph.ParagraphFormat.Style.Font;
f.Color = ColorTranslator.FromHtml(style.Color);
f.Italic = style.Style == “Italic” ? true : false;
f.Bold = style.Weight == “Bold” ? true : false;
f.Size = new Unit(style.Size).Value;
f.Name = style.Font;

Run run = new Run(doc, text ?? “”);
paragraph.Runs.Add(run);
cell.Paragraphs.Add(paragraph);

I don’t really know why all text changes?
I’m only using this method once.



Cheers,
Franke

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. This occurs because you are changing style and this style is used by other paragraphs in your document. I think that you should use Run.Font. Please see the following code;

cell = new Cell(doc);

Paragraph paragraph = new Paragraph(doc);

Run run = new Run(doc, text ?? "");

Font f = run.Font;

f.Color = ColorTranslator.FromHtml(style.Color);

f.Italic = style.Style == "Italic" ? true : false;

f.Bold = style.Weight == "Bold" ? true : false;

f.Size = new Unit(style.Size).Value;

f.Name = style.Font;

paragraph.Runs.Add(run);

cell.Paragraphs.Add(paragraph);

Hope this helps.

Best regards.