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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

124044 May 11,2016 03:54 AM May 17,2016 01:36 AM ASP.NET MVC 3
loading
Tags: DocIO
Testname
Asked On May 11, 2016 03:54 AM

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);
                columnCounter++;
            }

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

Sarathkumar V [Syncfusion]
Replied On May 12, 2016 05:32 AM

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:
http://www.syncfusion.com/downloads/support/forum/124044/ze/GenerateWord-2030752361.zip

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.

Regards,
Sarath 


Testname
Replied On May 13, 2016 01:46 AM

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
                        }
                    }
                    else
                    {

                        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;
                        }
                    }


                }
                x++;
            }

            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 ?


Vijay Ramachandran [Syncfusion]
Replied On May 16, 2016 07:55 AM

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.

Regards,
Vijay R


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;