Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Sep 28, 2019 1:51 pm

I've taken your sample of how to build a table, but I'm trying to make the first column HorizontalAlignment.Left and the other 4 columns HorizontalAlignment.Center.

Code: Select all
C Represents Column.
                for (int c = 0; c < data[r].Length; c++)
                {
                   DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    Paragraph p2 =DataRow.Cells[c].AddParagraph();
                    TextRange TR2=p2.AppendText(data[r][c]);
                    //Format Cells
                    p2.Format.HorizontalAlignment = HorizontalAlignment.Center;
                    TR2.CharacterFormat.FontName = "Calibri";
                    TR2.CharacterFormat.FontSize = 12;
                    TR2.CharacterFormat.TextColor = Color.Brown;
               }


Please could you help with the above, and also another problem I have is how to make the last Row contain all Bold text, but I think a solution on the above would also solve this problem.

Thanks

Wilshaw
 
Posts: 6
Joined: Fri May 17, 2019 8:44 pm

Sun Sep 29, 2019 6:09 am

Hi,

Thanks for your inquiry.
Please refer to following code:
Code: Select all
            for (int i = 0; i < table.Rows.Count; i++)
            {
                TableRow row = table.Rows[i];
                for (int j = 0; j < row.Cells.Count; j++)
                {
                    Paragraph p2 = row.Cells[j].AddParagraph();
                    p2.AppendText(j.ToString());

                    //set the alignment of paragraph in the first column as left
                    if (j == 0)
                    {
                        //Format Cells
                        p2.Format.HorizontalAlignment = HorizontalAlignment.Left;

                    }
                    //set the alignment of paragraph in other 4 column as center
                    else
                    {
                        //Format Cells
                        p2.Format.HorizontalAlignment = HorizontalAlignment.Center;
                    }

                }

            }

            //Get the last row
            TableRow lastRow = table.LastRow;
            for (int i = 0; i < lastRow.Cells.Count; i++)
            {
                foreach (DocumentObject obj in lastRow.Cells[i].Paragraphs[0].ChildObjects)
                {
                    if (obj is TextRange)
                    {
                        TextRange tr = obj as TextRange;
                        //Set bold
                        tr.CharacterFormat.Bold = true;
                    }
                }
            }


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Sun Sep 29, 2019 10:45 am

Perfect thanks - all working now.

Wilshaw
 
Posts: 6
Joined: Fri May 17, 2019 8:44 pm

Mon Sep 30, 2019 1:34 am

Hi,

Thanks for your feedback.
If there is any question, welcome to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc