Free Support Forum - aspose.com

How to change the font size in a table and table border style

How to change the font size in a table and table border style of the original document.I have code,But did not change after running.

foreach (Aspose.Words.Tables.Table t in doca.Sections[0].Body.Tables)
{
t.Alignment = Aspose.Words.Tables.TableAlignment.Center;
t.Style.Font.Size = 10.0f;
t.Style.Font.Italic = true;
//t.Style.ParagraphFormat.Borders is readonly,can not set??
}
I don't understand why paragraph set was not successful, but run set is successful, What's use of paragraph.Style.Font?
foreach (Aspose.Words.Paragraph p in doc.Sections[0].Body.Paragraphs)
{
p.ParagraphFormat.LeftIndent = 0;//changed successfully
p.ParagraphFormat.Style.Font.Bold = true;//test results have not changed successfully
foreach (Run run in p.GetChildNodes(NodeType.Run, true))
{
run.Font.Bold=true;//changed successfully
}
}

I have a text:Text is 12345 ABC,I want set “Text is” and “ABC” font is Times New Roman,set “12345” font is calibri,How to do it?

I have a text:“1 test title A”

"2 test title B"
I want delete “1” and “2”,What do I need to do?
Please give me an example by run or by paragraph.

Hi,


Thanks for your inquiry and sorry for the delayed response.

Please note that Aspose.Words represents the document as a tree of objects like an XML DOM tree. Please read the following articles for more information on DOM:
http://www.aspose.com/docs/display/wordsnet/Object+Model+Overview
http://www.aspose.com/docs/display/wordsnet/Composition+Diagrams
lovecomputer:
I have a text:“1 test title A”
"2 test title B"
I want delete “1” and “2”,What do I need to do?
All text of the document is stored in runs of text. Please use Run.Text Property to get or set the text of the run.

<span lang=“EN-GB” style=“font-family:“Courier New”;color:green;mso-ansi-language:EN-GB;
mso-no-proof:yes”>// Create an empty document. It contains one empty paragraph.<o:p></o:p>

Document doc = new Document();

// Create a new run of text.

Run run = new Run(doc, "Hello");

// Specify character formatting for the run of text.

Aspose.Words.Font f = run.Font;

f.Name = "Courier New";

f.Size = 36;

f.HighlightColor = Color.Yellow;

// Append the run of text to the end of the first paragraph

// in the body of the first section of the document.

doc.FirstSection.Body.FirstParagraph.AppendChild(run);


lovecomputer:
How to change the font size in a table and table border style of the original document.I have code,But did not change after running.
Please use the following code snippet for your requirement and read following documentation links for your kind reference.

http://www.aspose.com/docs/display/wordsnet/Applying+Formatting+to+Table%2C+Row+and+Cell
http://www.aspose.com/docs/display/wordsnet/Working+with+Table+Styles

Document doc = new Document(MyDir + "in.docx");

NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);

foreach (Table table in tables)

{

// Clear any existing borders from the table.

table.ClearBorders();

// Set a green border around the table but not inside.

table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, Color.Green, true);

table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, Color.Green, true);

table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, Color.Green, true);

table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, Color.Green, true);

NodeCollection runs = table.GetChildNodes(NodeType.Run, true);

foreach (Run run in runs)

{

//Change the font of table's cell

run.Font.Bold = true;

run.Font.Size = 10;

run.Font.Name = "Times New Roman";

}

}

doc.Save(MyDir + "AsposeOut.docx");

Hope this answers your query. Please let us know if you have any more queries.

Thank you for your answer, there is also the problem:I have text:"2.2Title",I would like to replase "2.2-Title".I have code,But the test was not successful, regular expression test was successful

foreach (Aspose.Words.Paragraph p in doc.Sections[0].Body.Paragraphs)
{

p.Runs[0].Range.Replace(new Regex(@"(?<=^\d+\.\d+)(?=\w)"), "-");

}

Hi,


Thanks for your query. Please make sure that “p.Runs[0]” contains correct text. It would be great if you please share your document for investigation purposes. I will share the code accordingly.

How do I get this parenthesis ①,I have a text"①test1,1.test2",In runs[0] is garbled,this is studio Development platform for test results:runs[0].Text" = 1 \\* GB3 1test\r",Also I found if a text font not the same, different in runs.

Hi,


Thanks for your query. All text of the document is stored in runs of text. Please use the DocumentExplorer to view Run nodes of your document.

Moreover, please note that DocumentExplorer is a very useful tool to see the entire document structure. You can find DocumentExplorer in the folder where you installed Aspose.Words e.g. C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe. Please see the attached image for details.

Please check my reply at following forum link for your kind reference.
https://forum.aspose.com/t/51261

Please share your document with us so that we can answer you in detail about your query.