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.

Fri May 05, 2017 8:43 am

i have a function about split tables cell
Code: Select all
   public void SplitTableCell(string bookmarkName, int tRow, int tColumn, int numRow, int numCol)
        {
            object bookmark = bookmarkName;
            object row = numRow;
            object col = numCol;
            Range rng = wordApp.ActiveDocument.Bookmarks.get_Item(ref bookmark).Range;
            rng.Tables[1].Cell(tRow, tColumn).Split(numRow, numCol);
        }


but, How to replace this method by Spire.Doc


thanks,
Ryan

ryanruan
 
Posts: 7
Joined: Sun Oct 09, 2016 2:04 am

Fri May 05, 2017 9:07 am

Dear Ryan,

Thanks for your inquiry.
Here is sample code for your kind reference.
Code: Select all
            //find the bookmark
            Bookmark bookmark = document.Bookmarks.FindByName("Row0C0");
            //get the cell which has that bookmark
            TableCell cell = bookmark.BookmarkStart.Owner.Owner as TableCell;
            //split the cell
            cell.SplitCell(2, 1);

If there is still the issue, please provide us with your input file for investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Mon May 08, 2017 10:31 am

hi Betsy,
i use another functin to insert a row, but the text style has changed,and how can i reset the text font and row space ? thanks.
Code: Select all
     
            Bookmark _bMark = doc.Bookmarks.FindByName(_bMarkName);
            Font font = new Font("宋体", 8, FontStyle.Regular);
            if (_bMark != null)
            {
                InsertTableRow(_bMarkName, _bMarkValue.Count - 1, 1);
                Paragraph _parag = _bMark.BookmarkStart.OwnerParagraph;
                TableCell _tCell = _parag.Owner as TableCell;
                TableRow _tRow = _tCell.OwnerRow as TableRow;
                Table _table = _tRow.Owner as Table;
                int index = 1;
                _bMarkValue.ForEach(delegate (string[] adInfo)
                {
                    for (int i = 0; i < adInfo.Length; i++)
                    {
                        TextRange tRange = _table.Rows[index].Cells[i].AddParagraph().AppendText(adInfo[i]);
                        tRange.CharacterFormat.Font = font;             
                    }
                    index += 1;
                });       
            }
       
Code: Select all
         public void InsertTableRow(string _bMarkName, int rowNum, int tRow = 1, int clnNum = 2)
        {
            Bookmark _bMark = doc.Bookmarks.FindByName(_bMarkName);
            if (_bMark != null)
            {
                Table table = _bMark.BookmarkStart.Owner.Owner.Owner.Owner as Table;
                for (int i = 0; i < rowNum; i++)
                {
                    TableRow row = table.AddRow(true, clnNum);
                    table.Rows.Insert(tRow, row);
                }
            }
        }

ryanruan
 
Posts: 7
Joined: Sun Oct 09, 2016 2:04 am

Tue May 09, 2017 6:57 am

Dear ryanruan,

Thanks for your inquiry.
Please note that the method AddRow() will copy the format of Row and Cell by default, but it cannot copy paragraph format in TableCell. So you need to reset the text style by yourself. And I checked the code you provided and found you already reset the text font using code tRange.CharacterFormat.Font = font, it worked on my side. Did you mean it cannot work on your side ?
And you can use following code to reset the row space.
Code: Select all
table.Rows[0].Height = 20;


Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue May 09, 2017 10:41 am

hi,Betsy,

oh,sorry,For my explain the mistake, i mean how to set the TextRange's format (like 2.jpg) by code?

like 1.jpg--->2.jpg
1.jpg
to
2.jpg


thanks for helping.

ryanruan
 
Posts: 7
Joined: Sun Oct 09, 2016 2:04 am

Wed May 10, 2017 6:05 am

Dear ryanruan,

Thanks for the information.
From the screenshot you provided, I only see there is the font change for the TextRange. And for the paragraph existed in table cell, please firstly get the TextRange of the paragraph and then reset the format.
Here is sample code for your reference.
Code: Select all
                    TableCell cell = table.Rows[i].Cells[j];
                    foreach (Paragraph para in cell.Paragraphs)
                    {
                        foreach (DocumentObject obj in para.ChildObjects)
                        {
                            if(obj is TextRange)
                            {
                                TextRange tr = obj as TextRange;
                                tr.CharacterFormat.Font = font;
                            }
                        }
                    }

Hope this can help. If you still have issues, please provide input Word document and the expected Word document(you can generate it by MS Word ) for investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Thu May 11, 2017 3:53 am

hi Betsy,

sorry for that, the last question, how to set the TableCell paragraph's Line spacing & At in spire.doc

like this :
1.png


thanks for you helping,
Ryan

ryanruan
 
Posts: 7
Joined: Sun Oct 09, 2016 2:04 am

Thu May 11, 2017 7:05 am

Dear Ryan,

Thanks for your response.
Please use following code to set Line spacing.
Code: Select all
para.Format.LineSpacing = 100;


Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.Doc