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 Dec 31, 2022 5:01 am

Hi!

I'm trying to make a table in this format, but it's coming out the same as below.

The header is giving a space that I am not able to remove.

The table must have 12 columns.


When I open Word I have to go to Scale and remove that space.

Can anybody help me.

Follow the code.


Code: Select all

          Document doc = new Document();
            doc.LoadFromFile("C:\\Temp\\Dev.docx");

            Section section = doc.Sections[0];

            TextSelection selection = doc.FindString("@TABELA_LOTES_VOLUME", true, true);
            TextRange range = selection.GetAsOneRange();
            Paragraph paragraph = range.OwnerParagraph;
            Body body = paragraph.OwnerTextBody;
            int index = body.ChildObjects.IndexOf(paragraph);
           
            //FAZER O LOOP
            Spire.Doc.Table table = section.AddTable(true);

            int totalColuna = 12;
            int totalLinhas = 2;
            table.ResetCells(totalLinhas, totalColuna);

            body.ChildObjects.Remove(paragraph);
            body.ChildObjects.Insert(index, table);

            //Set the first row as table header
            TableRow FRow = table.Rows[0];
            FRow.IsHeader = true;

            //Set the height and color of the first row
            FRow.Height = 23;
            FRow.RowFormat.BackColor = Color.FromArgb(102, 102, 102);
            FRow.RowFormat.CellSpacing = 0;
           
            String[] Header = { "COLUNA 1", "COLUNA 2", "COLUNA 3", "COLUNA 4", "COLUNA 5", "COLUNA 6", "COLUNA 7", "COLUNA 8", "COLUNA 9", "COLUNA 10", "COLUNA 11", "COLUNA 12" };

            for (int i = 0; i < Header.Length; i++)
            {
                //Set alignment for cells
                Paragraph p = FRow.Cells[i].AddParagraph();
                FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                p.Format.HorizontalAlignment = HorizontalAlignment.Center;
                p.Format.WordWrap = true;
                p.RemoveFrame();
                p.RemoveAbsPosition();
               
                //Set data format
                TextRange TR = p.AppendText(Header[i]);
               
                TR.CharacterFormat.FontSize = 10;
                TR.CharacterFormat.Bold = true;
            }

            doc.SaveToFile("C:\\Temp\\Docmento1.docx", Spire.Doc.FileFormat.Docx);


rafaelmoraes
 
Posts: 2
Joined: Sat Dec 31, 2022 4:47 am

Tue Jan 03, 2023 9:31 am

Hi,

Thanks for your inquiry.
I did a test with the code you provided, but I did not reproduce your issue, you can see the following picture.
result.png

To help us work out a solution for you, could you please provide us with the following messages? You can send them to us via email ([email protected]) or attach them here. Thanks for your assistance in advance.
1) your input files.
2) the version of Spire.Doc in your project.
3) your test environment, such as Windows 10 64bit.
4) the version of MS Word you use.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Jan 09, 2023 7:15 am

Hi,

Greetings from E-iceblue.
How is your issue going now? Could you please give us some feedback at your convenience? If the issue hasn’t been solved, please provide us with the following messages.
1) your input files.
2) the version of Spire.Doc in your project.
3) your test environment, such as Windows 10 64bit.
4) the version of MS Word you use.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Jan 11, 2023 2:59 pm

Hi, I used it

p.Format.SetLeftIndent(0);

and it worked perfectly removing the spaces on the left side.

Thanks

rafaelmoraes
 
Posts: 2
Joined: Sat Dec 31, 2022 4:47 am

Thu Jan 12, 2023 7:27 am

Hi,

Thanks for your feedback.
We are glad to hear that your issue was solved. Once there are any other questions, just feel free to contact us.
Have a nice day! :D

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc