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.

Tue Aug 27, 2019 12:56 pm

Hi! In my ASP.NET MVC application I have a problem with table cells in the last column. Img in attachments
27.08.png
. Part of code:
Code: Select all
using (MemoryStream stream = new MemoryStream())
            {
                Document document = new Document();
                Section section = document.AddSection();
                section.PageSetup.Orientation = Spire.Doc.Documents.PageOrientation.Landscape;

                Paragraph par = section.AddParagraph();
                par.Format.HorizontalAlignment = HorizontalAlignment.Center;

                TextRange tr = par.AppendText("Test\n" + date.ToShortDateString());
                tr.CharacterFormat.FontName = "Times New Roman";
                tr.CharacterFormat.FontSize = 14;
                tr.CharacterFormat.Bold = true;               

                section.AddParagraph();

                Table table1 = section.AddTable(true);
                string[] Header =  { "1","1","1","1","1","1","1","1","1","1","1","1","1" };

                table1.ResetCells(3, 11);
                TableRow row1 = table1.Rows[0];
                TableRow row2 = table1.Rows[1];
                TableRow row3 = table1.Rows[2];
                table1.TableFormat.Paddings.All = 0;

                ParagraphStyle style = new ParagraphStyle(document);
                style.Name = "AbonentTableStyle";
                style.CharacterFormat.FontSize = 12;
                style.CharacterFormat.FontName = "Times New Roman";
                style.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
                //style.ParagraphFormat.TextAlignment = TextAlignment.Center;
                document.Styles.Add(style);

                for (int i = 0; i < 11; i++)
                {
                    Paragraph p1 = row1.Cells[i].AddParagraph();
                    Paragraph p2 = row2.Cells[i].AddParagraph();
                    Paragraph p3 = row3.Cells[i].AddParagraph();

                    row1.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    row2.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    row3.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;

                    row1.Cells[0].SetCellWidth(3, CellWidthType.Percentage);
                    row2.Cells[0].SetCellWidth(3, CellWidthType.Percentage);
                    row3.Cells[0].SetCellWidth(3, CellWidthType.Percentage);

                    p1.ApplyStyle(style.Name);
                    p2.ApplyStyle(style.Name);
                    p3.ApplyStyle(style.Name);

                    TextRange TR1 = null;
                    TextRange TR2 = null;
                    TextRange TR3 = null;

                    if (i < 6)
                    {
                        TR1 = p1.AppendText(Header[i]);
                    }
                    else
                    {
                        if (i == 6)
                        {
                            TR1 = p1.AppendText(Header[6]);
                            TR2 = p2.AppendText(Header[7]);
                        }
                        else if (i == 7)
                        {
                            TR2 = p2.AppendText(Header[8]);
                        }
                        else if (i == 8)
                        {
                            TR2 = p2.AppendText(Header[9]);
                            TR3 = p3.AppendText(Header[10]);
                        }
                        else if (i == 9)
                        {
                            TR3 = p3.AppendText(Header[11]);
                        }
                        else
                        {
                            TR1 = p1.AppendText(Header[12]);
                        }
                    } 
                }
                table1.ApplyVerticalMerge(0, 0, 2);
                table1.ApplyVerticalMerge(1, 0, 2);
                table1.ApplyVerticalMerge(2, 0, 2);
                table1.ApplyVerticalMerge(3, 0, 2);
                table1.ApplyVerticalMerge(4, 0, 2);
                table1.ApplyVerticalMerge(5, 0, 2);
                table1.ApplyHorizontalMerge(0, 6, 9);
                table1.ApplyVerticalMerge(6, 1, 2);
                table1.ApplyVerticalMerge(7, 1, 2);
                table1.ApplyHorizontalMerge(1, 8, 9);
                table1.ApplyVerticalMerge(10, 0, 2); // Incorrect merging

                document.SaveToStream(stream, FileFormat.Doc);
}

niksamoyloff
 
Posts: 2
Joined: Tue Aug 27, 2019 12:22 pm

Wed Aug 28, 2019 3:45 am

Hi,

Thanks for your inquiry.
After testing your case with the latest Spire.Doc Pack(hot fix) Version:7.8.12, I found when saving to .docx file, there is no issue. But when saving to .doc format file, the merged cell was incorrect. I have logged this issue to our bug tracking system, we will let you know once there is any update.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Wed Aug 28, 2019 6:36 am

Hello! Thanks a lot!

niksamoyloff
 
Posts: 2
Joined: Tue Aug 27, 2019 12:22 pm

Return to Spire.Doc