We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

I need something like "ImportArray" for a word table.

If I have a List of string arrays, how can I fill a word table dynamically like this in excel:

   List<MyCustomClass> tempMyCustomClasse = _dokEigenschaften.MyCustomClasse;

            int columnCounter = 1;
            foreach (MyCustomClass item in tempMyCustomClasse)
                worksheet.ImportArray(item.Werte, 1, columnCounter, true);

I need something like "ImportArray" for a word table.

3 Replies

SV Sarathkumar V Syncfusion Team May 12, 2016 09:32 AM UTC

Hi Customer,

Currently DocIO does not have any specific API similar to IWorksheet.ImportArray(), but DocIO can achieve your requirement in sample level . We have prepared a sample to import the string array collection into Word table similar to IWorksheet.ImportArray(). Please find the sample from the below link and let us know if it helps.

Sample Link:

If we misunderstood any of your requirement, then kindly elaborate the actual requirement with detailed description. Thereby we will analyze further on the mentioned case and will provided you appropriate solution.


TE Testname May 13, 2016 05:46 AM UTC

Yes, thats great, I changed my code to :

 WordDocument doc = new WordDocument();

            IWSection section = doc.AddSection();

            int maxRowCount = GetMaxZeilenAnzahl(singleTable);
            int maxCellCount = singleTable.Count;

            IWTable table = section.AddTable();
            table.TableFormat.IsAutoResized = true;
            table.TableFormat.Borders.BorderType = BorderStyle.Single;

            table.ResetCells(maxRowCount, maxCellCount);

            int x = 0;

            //Merge the array content into the table
            foreach (Excelwert item in singleTable)
                for (int y = 0; y < item.Werte.Length; y++)

                    if (item.Summenspalte && y == item.Werte.Length - 1) //letzte Zeile
                        int xWidth = singleTable.Count;
                        //table.LastRow.RowFormat.Borders.Top.LineWidth = 2.5f; //todo:this does not work, please change so that I do not have to use "for" loop

                        for (int cellCounter = 0; cellCounter < xWidth; cellCounter++)
                            table[y, cellCounter].CellFormat.Borders.Top.LineWidth = 1.5f;

                        IWTextRange textRangeGesamtergebnis = table[y, x].AddParagraph().AppendText(item.Werte[y]);
                        textRangeGesamtergebnis.CharacterFormat.FontName = "Verdana";
                        textRangeGesamtergebnis.CharacterFormat.FontSize = 8;
                        textRangeGesamtergebnis.CharacterFormat.Bold = true;
                        textRangeGesamtergebnis.CharacterFormat.UnderlineStyle = UnderlineStyle.Single;

                        IWTextRange textRangeText = table[y, x - 1].AddParagraph().AppendText(item.Werte[y]);
                        textRangeText.Text = "Gesamtvolumen";
                        textRangeText.CharacterFormat.FontName = "Verdana";
                        textRangeText.CharacterFormat.FontSize = 8;

                        if (xWidth > 3) //todo: check that I never run into an exception, if the cell does not exist
                            table.ApplyHorizontalMerge(y, 0, xWidth - 3); //mergen von cell

                        IWTextRange textRange = table[y, x].AddParagraph().AppendText(item.Werte[y]);
                        textRange.CharacterFormat.FontName = "Verdana";
                        textRange.CharacterFormat.FontSize = 8;

                        if (y == 0) //1. Zeile
                            textRange.CharacterFormat.Bold = true;


            return doc;

Please take a look at my todo's and fix as well I need the table to fulfill the entire width it does not matter whether it is landscape or portrait, by the way how can I center a table ?

VR Vijay Ramachandran Syncfusion Team May 16, 2016 11:55 AM UTC

Hi Customer,

Thank you for your update.

Kindly provide us current output Word document and your expected output with clear details. Thereby
we will analyse further and will provided you appropriate solution.

Vijay R

Live Chat Icon For mobile
Up arrow icon