DocIO - working with tables
Hello,
I am working on a WPF project and using syncfusion DocIO I am creating a table in a word Document. I am a beginner and I don't manage to change the fontsize of all the cells of my table. Is textRange.CharacterFormat.FontSize available for the paragraphs I added on my cells ? I have tried without succees. Below, an extract of my code :
private WTable InsererTableau(WordDocument document)
{
WTable tableauRdc = new WTable(document);
tableauRdc.Description = "Relevé de carrière passées et futures";
tableauRdc.TableFormat.IsAutoResized = true;
tableauRdc.TableFormat.HorizontalAlignment = RowAlignment.Center;
tableauRdc.TableFormat.Paddings.All = 5;
tableauRdc.TableFormat.Borders.LineWidth = 1f;
tableauRdc.TableFormat.Borders.Color = Color.Orange;
tableauRdc.ApplyStyleForHeaderRow = true;
{
WTable tableauRdc = new WTable(document);
tableauRdc.Description = "Relevé de carrière passées et futures";
tableauRdc.TableFormat.IsAutoResized = true;
tableauRdc.TableFormat.HorizontalAlignment = RowAlignment.Center;
tableauRdc.TableFormat.Paddings.All = 5;
tableauRdc.TableFormat.Borders.LineWidth = 1f;
tableauRdc.TableFormat.Borders.Color = Color.Orange;
tableauRdc.ApplyStyleForHeaderRow = true;
if (Item.AnneeCarriere != null)
{
WTableRow row = tableauRdc.AddRow();
row.IsHeader = true;
row.RowFormat.BackColor = Color.WhiteSmoke;
WTableCell cell = row.AddCell();
cell.AddParagraph().AppendText("Année");
cell = row.AddCell();
cell.AddParagraph().AppendText("Régime");
cell = row.AddCell();
cell.AddParagraph().AppendText("Revenu annuel");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de trimestres");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de points Arrco");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de points Agirc");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de points autres");
WTableRow row = tableauRdc.AddRow();
row.IsHeader = true;
row.RowFormat.BackColor = Color.WhiteSmoke;
WTableCell cell = row.AddCell();
cell.AddParagraph().AppendText("Année");
cell = row.AddCell();
cell.AddParagraph().AppendText("Régime");
cell = row.AddCell();
cell.AddParagraph().AppendText("Revenu annuel");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de trimestres");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de points Arrco");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de points Agirc");
cell = row.AddCell();
cell.AddParagraph().AppendText("Nb de points autres");
foreach (WTableCell cel in row.Cells)
{
cel.CellFormat.VerticalAlignment = VerticalAlignment.Middle;
cel.CellFormat.Paddings.All = 0;
{
cel.CellFormat.VerticalAlignment = VerticalAlignment.Middle;
cel.CellFormat.Paddings.All = 0;
foreach (WParagraph paragraph in cel.Paragraphs)
{
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
{
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
}
} Could anyone be so kind to help me ? Thanks in advance for your answers. Kind regards Beatrice
} Could anyone be so kind to help me ? Thanks in advance for your answers. Kind regards Beatrice
SIGN IN To post a reply.
2 Replies
MJ
Mohanaselvam Jothi
Syncfusion Team
May 17, 2019 04:22 AM UTC
Hi Beatrice,
To achieve your requirement, we suggest you iterate into paragraph elements and set font size for text (WTextRange). Please refer the below code snippet to achieve this at your end:
To achieve your requirement, we suggest you iterate into paragraph elements and set font size for text (WTextRange). Please refer the below code snippet to achieve this at your end:
|
foreach (WParagraph paragraph in cel.Paragraphs)
{
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
foreach(ParagraphItem paragraphItem in paragraph)
{
if(paragraphItem is WTextRange)
{
WTextRange textRange = paragraphItem as WTextRange;
textRange.CharacterFormat.FontSize = 10f;
}
}
} |
Please refer our documentation link to know more about working with text in the Word document using DocIO:
https://help.syncfusion.com/file-formats/docio/working-with-paragraph#working-with-text
https://help.syncfusion.com/file-formats/docio/working-with-tables
Please let us know if you have any other questions.
Regards,
Mohanaselvam J
BD
Béatrice Daems
May 17, 2019 08:40 AM UTC
Thank you very much for your answer.
Kind regards,
Beatrice
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
BD Béatrice Daems
- May 16, 2019 09:38 AM UTC
- May 17, 2019 08:40 AM UTC