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.

Sun Oct 22, 2017 8:29 am

The error is "Index was out of range. Must be non negative and less than the size of the collection. Parameter name index"

Code: Select all
   Document headerDoc = new Document ( Application.StartupPath + "\\headerWH.docx" ) ;
            Document doc = new Document () ;
            Section s = doc.AddSection () ;
            foreach (Section sec in headerDoc.Sections)
            {
                for (int i = 0; i < sec.Body.ChildObjects.Count; i++)
                {
                    doc.Sections[0].Body.ChildObjects.Add(sec.Body.ChildObjects[i].Clone());
                }
            }

            Table table = s.AddTable(true) ;
            doc.Sections[0].PageSetup.Margins.Left = 35.9F;
            doc.Sections[0].PageSetup.Margins.Right = 35.9F;
            doc.Sections[0].PageSetup.Orientation = PageOrientation.Landscape;
            String[] Header = {"ሀ)ተ.ቁ (No)","ለ)የግብር ከፋዩ መለያ ቁጥር (TIN)","ሐ)ግብር ተቀናሽ የተደረገበት ሰው/ ድርጅት ሙሉ ስም (Supplier)",
                "መ)አድራሻ","ሠ)የገቢ ዓይነት /ከህንጻ ኪራይ / ሌሎች/ (Income Type)","ረ)የተከፋይ መጠን (Amount)","ሰ)ተቀናሽ የተደረገ ግብር (Withheld Amount) (2 %)",
                "ሸ)ከተከፋይ ሂሳብ ላይ ለተቀነሰ ግብር የተሰጠ ደረሰኝ" };
            String[] Header2 = { "ክልል (Region)", "ዞን / ክፍለ ከተማ (Subcity)", "ወረዳ (Woreda)",
                "ቀበሌ / ገበሬ ማሀበር (Kebele)", "የቤት ቁጥር (H.No)", "የደረሰኝ ቁጥር (Reciept No)", "ቀን Date"};

            int rs = dataGridView1.Rows.Count;
            int cs = dataGridView1.Columns.Count;
            String[][] data = new String[rs][];
            double totalamount = 0;
            double totalwithholding = 0;
            double firstpageamount = 0;
            double firstpagewh = 0;
            double totalotherpagewh = 0;
            double totalotehrpageamount = 0;
            int max = 7;
            if (data.Length < 7)             
                max = data.Length;         
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells[9].Value != null)
                {
                    totalamount += Double.Parse(dataGridView1.Rows[i].Cells[9].Value.ToString());
                    if (i >= max)
                        totalotehrpageamount += Double.Parse(dataGridView1.Rows[i].Cells[9].Value.ToString());
                    if (i < max)
                        firstpageamount  += Double.Parse(dataGridView1.Rows[i].Cells[9].Value.ToString());
                }
                if (dataGridView1.Rows[i].Cells[10].Value != null)
                {
                    totalwithholding += Double.Parse(dataGridView1.Rows[i].Cells[10].Value.ToString());
                    if (i >= max)
                        totalotherpagewh += Double.Parse(dataGridView1.Rows[i].Cells[10].Value.ToString());
                    if (i < max)
                        firstpagewh += Double.Parse(dataGridView1.Rows[i].Cells[9].Value.ToString());
                }
                data[i] = new String[13];
                for (int j = 0 ; j < 13 ; j++)
                {
                    if (j == 12)
                        data[i][j] = dataGridView1.Rows[i].Cells[13].Value.ToString() + " " + dataGridView1.Rows[i].Cells[12].Value.ToString() + ", " + dataGridView1.Rows[i].Cells[14].Value.ToString();
                    else if (j == 1)
                        data[i][2] = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    else if (j == 2)
                        data[i][1] = dataGridView1.Rows[i].Cells[2].Value.ToString();
                    else if ( j == 9 || j == 10 )
                    {
                        try
                        {
                            data[i][j] = String.Format("{0:N}", Double.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()));
                        }
                        catch
                        {
                            data[i][j] = "0.00";
                        }
                    }
                    else
                    {
                        if (dataGridView1.Rows[i].Cells[j].Value != null)
                            data[i][j] = dataGridView1.Rows[i].Cells[j].Value.ToString();
                        else
                            data[i][j] = "";
                    }
                }
            }
            table.ResetCells(max+4, 13);
            TableRow FRow = table.Rows[0];
            TableRow FRow2 = table.Rows[1];
            table.ApplyVerticalMerge(0, 0, 1);
            table.ApplyVerticalMerge(1, 0, 1);
            table.ApplyVerticalMerge(2, 0, 1);
            table.ApplyVerticalMerge(8, 0, 1);
            table.ApplyVerticalMerge(9, 0, 1);
            table.ApplyVerticalMerge(10, 0, 1);
            table.ApplyHorizontalMerge(0, 3, 7);
            table.ApplyHorizontalMerge(0, 11, 12);
            table.ApplyHorizontalMerge(max + 2, 0, 8);
            table.ApplyHorizontalMerge(max + 2, 11, 12);
            table.ApplyHorizontalMerge(max + 3, 0, 8);
            table.ApplyHorizontalMerge(max + 3, 11, 12);
            FRow.IsHeader = true;
            FRow.Height = 18;
            FRow2.IsHeader = true;
            FRow2.Height = 18;
            for (int i = 0; i < 8; i++)
            {
                Paragraph p;
                if (i == 0)
                    FRow.Cells[i].Width = 10;
                if (i == 1 || i == 2)
                    FRow.Cells[i].Width = 75;
                if (i == 4 || i == 5 || i == 6 || i == 7)
                {
                    FRow.Cells[i + 4].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    p = FRow.Cells[i + 4].AddParagraph();
                }
                else
                    p = FRow.Cells[i].AddParagraph();
                FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                TextRange TR = p.AppendText(Header[i]);
                TR.CharacterFormat.FontName = "Calibri";
                TR.CharacterFormat.FontSize = 8;
                TR.CharacterFormat.TextColor = Color.Black;
                TR.CharacterFormat.Bold = true;
            }
            for (int i = 0; i < 7; i++)
            {

                Paragraph p = null ;
                if (i >= 0 && i <= 4)   
                    p = FRow2.Cells[i + 3].AddParagraph() ;
                else
                    p = FRow2.Cells[i + 6].AddParagraph() ;
                if (i + 6 == 12)
                    FRow2.Cells[i + 6].Width = 75 ;

                FRow2.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                TextRange TR = p.AppendText(Header2[i]);
                TR.CharacterFormat.FontName = "Calibri";
                TR.CharacterFormat.FontSize = 8;
                TR.CharacterFormat.TextColor = Color.Black;
                TR.CharacterFormat.Bold = true;

            }
            for (int r = 0; r <= max + 1; r++)
            {
                TableRow DataRow = table.Rows[r + 2];
                DataRow.Height = 14;
                if (r == max)     
                {
                    Paragraph p2 = DataRow.Cells[0].AddParagraph();
                    TextRange TR2 = p2.AppendText("ሌሎች አባሪ ገጾች ድምር");
                    TR2.CharacterFormat.FontName = "Calibri";
                    TR2.CharacterFormat.FontSize = 8;
                    TR2.CharacterFormat.TextColor = Color.Black;
                    TR2.CharacterFormat.Bold = true;
                    DataRow.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;

                    Paragraph p4 = DataRow.Cells[9].AddParagraph();
                    TextRange TR4 = p4.AppendText(String.Format("{0:N}", totalotehrpageamount));
                    TR4.CharacterFormat.FontName = "Calibri";
                    TR4.CharacterFormat.FontSize = 8;
                    TR4.CharacterFormat.TextColor = Color.Black;
                    TR4.CharacterFormat.Bold = true;
                    p4.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
                    DataRow.Cells[9].CellFormat.VerticalAlignment = VerticalAlignment.Middle;

                    Paragraph p6 = DataRow.Cells[10].AddParagraph();
                    TextRange TR6 = p6.AppendText(String.Format("{0:N}", totalotherpagewh ));
                    TR6.CharacterFormat.FontName = "Calibri";
                    TR6.CharacterFormat.FontSize = 8;
                    TR6.CharacterFormat.TextColor = Color.Black;
                    TR6.CharacterFormat.Bold = true;
                    p6.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
                    DataRow.Cells[10].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                }
                else if (r == max + 1)
                {
                    Paragraph p2 = DataRow.Cells[0].AddParagraph();
                    TextRange TR2 = p2.AppendText ("ጠቅላላ ድምር (ረ)እና (ሰ)(Line 20 and 30)");
                    TR2.CharacterFormat.FontName = "Calibri";
                    TR2.CharacterFormat.FontSize = 8;
                    TR2.CharacterFormat.TextColor = Color.Black;
                    TR2.CharacterFormat.Bold = true;
                    DataRow.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;

                    Paragraph p4 = DataRow.Cells[9].AddParagraph();
                    TextRange TR4 = p4.AppendText(String.Format("{0:N}", totalamount));
                    TR4.CharacterFormat.FontName = "Calibri";
                    TR4.CharacterFormat.FontSize = 8;
                    TR4.CharacterFormat.TextColor = Color.Black;
                    TR4.CharacterFormat.Bold = true;
                    p4.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
                    DataRow.Cells[9].CellFormat.VerticalAlignment = VerticalAlignment.Middle;

                    Paragraph p6 = DataRow.Cells[10].AddParagraph();
                    TextRange TR6 = p6.AppendText(String.Format("{0:N}", totalwithholding ));
                    TR6.CharacterFormat.FontName = "Calibri";
                    TR6.CharacterFormat.FontSize = 8;
                    TR6.CharacterFormat.TextColor = Color.Black;
                    TR6.CharacterFormat.Bold = true;
                    p6.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
                    DataRow.Cells[10].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                }
                else
                {
                    for (int c = 0; c < 13 ; c++)
                    {
                        if ( c == 0 )
                            DataRow.Cells[c].Width = 10 ;
                        if ( c == 1 || c == 2 || c == 8 )   
                        {
                            FRow.Cells[c].Width = 75;
                            DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                            Paragraph p2 = DataRow.Cells[c].AddParagraph();
                            TextRange TR2 = p2.AppendText(data[r][c]);
                            p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                            TR2.CharacterFormat.FontName = "Calibri";
                            TR2.CharacterFormat.FontSize = 8;
                            TR2.CharacterFormat.TextColor = Color.Black;
                        }
                        else
                        {
                            DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                            Paragraph p2 = DataRow.Cells[c].AddParagraph();
                            TextRange TR2 = p2.AppendText(data[r][c]);
                            p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
                            TR2.CharacterFormat.FontName = "Calibri";
                            TR2.CharacterFormat.FontSize = 8;
                            TR2.CharacterFormat.TextColor = Color.Black;
                        }
                    }
                }
            }

            Document footerDoc = new Document (Application.StartupPath + "\\footerWH.docx");
            foreach (Section sec in footerDoc.Sections)
            {
                for (int i = 0; i < sec.Body.ChildObjects.Count; i++)
                {
                    doc.Sections[0].Body.ChildObjects.Add(sec.Body.ChildObjects[i].Clone());
                }

                //Paragraph p1 = doc.Sections[0].Tables[0].Rows[0].Cells[2].AddParagraph();
                //MessageBox.Show(doc.Sections[0].Tables[0].Rows[0].Cells[2].Paragraphs[0].Text);

                Paragraph p1 = doc.Sections[0].Tables[3].Rows[0].Cells[2].AddParagraph();
                TextRange TR1 = p1.AppendText(cs.ToString ());
                TR1.CharacterFormat.FontName = "Calibri";
                TR1.CharacterFormat.FontSize = 8;
                TR1.CharacterFormat.TextColor = Color.Black;
                TR1.CharacterFormat.Bold = true;

                Paragraph p2 = doc.Sections[0].Tables[3].Rows[1].Cells[2].AddParagraph();
                TextRange TR2 = p2.AppendText(String.Format("{0:N}", totalamount));
                TR2.CharacterFormat.FontName = "Calibri";
                TR2.CharacterFormat.FontSize = 8;
                TR2.CharacterFormat.TextColor = Color.Black;
                TR2.CharacterFormat.Bold = true;

                Paragraph p3 = doc.Sections[0].Tables[3].Rows[2].Cells[2].AddParagraph();
                TextRange TR3 = p3.AppendText(String.Format("{0:N}",totalwithholding));
                TR3.CharacterFormat.FontName = "Calibri";
                TR3.CharacterFormat.FontSize = 8;
                TR3.CharacterFormat.TextColor = Color.Black;
                TR3.CharacterFormat.Bold = true;

                DateTime dt = DateTime.Now;
                string date = "";
                if (calendar == "Ethiopian")
                    date = EthiopianCalendar.Conversion.EthiopianDateConverter.ToEthiopianDate(dt).ToShortDateString() + " E.C.";
                if (calendar == "Gregorian")
                    date = dt.ToShortDateString() + " G.C.";
                Paragraph p4 = doc.Sections[0].Tables[4].Rows[0].Cells[0].Paragraphs[1];
                TextRange TR4 = p4.AppendText(date.ToString());
                TR4.CharacterFormat.FontName = "Calibri";
                TR4.CharacterFormat.FontSize = 8;
                TR4.CharacterFormat.TextColor = Color.Black;
                TR4.CharacterFormat.Bold = true; 

            }

            Document headerDoc2 = new Document(Application.StartupPath + "\\headerWHPage2.docx");
            Section s2 = doc.AddSection();
            foreach (Section sec in headerDoc2.Sections)
            {
                for (int i = 0; i < sec.Body.ChildObjects.Count; i++)
                {
                      doc.Sections[1].Body.ChildObjects.Add(sec.Body.ChildObjects[i].Clone());
                }
            }

            Table table2 = s2.AddTable(true);
            doc.Sections[1].PageSetup.Margins.Top = 35.9F;
            doc.Sections[1].PageSetup.Margins.Bottom = 35.9F;
            doc.Sections[1].PageSetup.Margins.Left = 35.9F;
            doc.Sections[1].PageSetup.Margins.Right = 35.9F;
            doc.Sections[1].PageSetup.Orientation = PageOrientation.Landscape;
            String[] secHeader = {"ሀ)ተ.ቁ (No)","ለ)የግብር ከፋዩ መለያ ቁጥር (TIN)","ሐ)ግብር ተቀናሽ የተደረገበት ሰው/ ድርጅት ሙሉ ስም (Supplier)",
                "መ)አድራሻ","ሠ)የገቢ ዓይነት /ከህንጻ ኪራይ / ሌሎች/ (Income Type)","ረ)የተከፋይ መጠን (Amount)","ሰ)ተቀናሽ የተደረገ ግብር (Withheld Amount) (2 %)",
                "ሸ)ከተከፋይ ሂሳብ ላይ ለተቀነሰ ግብር የተሰጠ ደረሰኝ" };
            String[] secHeader2 = { "ክልል (Region)", "ዞን / ክፍለ ከተማ (Subcity)", "ወረዳ (Woreda)",
                "ቀበሌ / ገበሬ ማሀበር (Kebele)", "የቤት ቁጥር (H.No)", "የደረሰኝ ቁጥር (Reciept No)", "ቀን (Date)"};
            if (data.Length > 7)
            {
                table2.ResetCells(data.Length - max + 2, 13);
                TableRow twoFRow = table2.Rows[0];
                TableRow twoFRow2 = table2.Rows[1];

                table2.ApplyVerticalMerge(0, 0, 1);
                table2.ApplyVerticalMerge(1, 0, 1);
                table2.ApplyVerticalMerge(2, 0, 1);
                table2.ApplyVerticalMerge(8, 0, 1);
                table2.ApplyVerticalMerge(9, 0, 1);
                table2.ApplyVerticalMerge(10, 0, 1);

                table2.ApplyHorizontalMerge(0, 3, 7);
                table2.ApplyHorizontalMerge(0, 11, 12);

                //table2.ApplyHorizontalMerge(table2.Rows.Count - 2, 0, 8);
                //table2.ApplyHorizontalMerge(table2.Rows.Count - 2, 11, 12);
                //table2.ApplyHorizontalMerge(table.Rows.Count - 1, 0, 8);
                //table2.ApplyHorizontalMerge(table.Rows.Count - 1, 11, 12);

                twoFRow.IsHeader = true;
                twoFRow.Height = 18;
                twoFRow2.IsHeader = true;
                twoFRow2.Height = 18;

                for (int i = 0; i < 8; i++)
                {
                    Paragraph p;
                    if (i == 0)
                        twoFRow.Cells[i].Width = 10;
                    if (i == 1 || i == 2)
                        twoFRow.Cells[i].Width = 75;
                    if (i == 4 || i == 5 || i == 6 || i == 7)
                    {
                        twoFRow.Cells[i + 4].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                        p = twoFRow.Cells[i + 4].AddParagraph();
                    }
                    else
                        p = twoFRow.Cells[i].AddParagraph();

                    twoFRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                    TextRange TR = p.AppendText(Header[i]);
                    TR.CharacterFormat.FontName = "Calibri";
                    TR.CharacterFormat.FontSize = 8;
                    TR.CharacterFormat.TextColor = Color.Black;
                    TR.CharacterFormat.Bold = true;
                }
                for (int i = 0; i < 7; i++)
                {
                    Paragraph p = null;
                    if (i >= 0 && i <= 4)
                        p = twoFRow2.Cells[i + 3].AddParagraph();
                    else
                        p = twoFRow2.Cells[i + 6].AddParagraph();
                    if (i + 6 == 12)
                        twoFRow2.Cells[i + 6].Width = 75;

                    twoFRow2.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                    TextRange TR = p.AppendText(Header2[i]);
                    TR.CharacterFormat.FontName = "Calibri";
                    TR.CharacterFormat.FontSize = 8;
                    TR.CharacterFormat.TextColor = Color.Black;
                    TR.CharacterFormat.Bold = true;
                }

                for (int r = 0; r<data .Length-max ; r++)
                {
                    TableRow DataRow = table2.Rows[r + 2];
                    DataRow.Height = 14;
                    for (int c = 0; c < data[r].Length; c++)
                    {
                        if (c == 0)
                            DataRow.Cells[c].Width = 10;
                        if (c == 1 || c == 2 || c == 8)
                        {
                            FRow.Cells[c].Width = 75;
                            DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                            Paragraph p2 = DataRow.Cells[c].AddParagraph();
                            TextRange TR2 = p2.AppendText(data[r+max][c]);
                            p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                            TR2.CharacterFormat.FontName = "Calibri";
                            TR2.CharacterFormat.FontSize = 8;
                            TR2.CharacterFormat.TextColor = Color.Black;
                        }
                        else
                        {
                            DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                            Paragraph p2 = DataRow.Cells[c].AddParagraph();
                            TextRange TR2 = p2.AppendText(data[r+max][c]);
                            p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
                            TR2.CharacterFormat.FontName = "Calibri";
                            TR2.CharacterFormat.FontSize = 8;
                            TR2.CharacterFormat.TextColor = Color.Black;
                        }   
                    }   
                }
            }

            try
            {   
                string origFileName = Path.Combine (Application.StartupPath, "Declerations", c, y, m, "WH.docx");
                doc.SaveToFile ( origFileName, FileFormat.Docx ) ;
                string directory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string origFileName2 = Path.Combine(directory, "VirtualStore", "Program Files (x86)", "Tonetor Cyberbiz", "Tonetor Tax Decleration", "Declerations", c, y, m, "WH.docx");

                if (File.Exists(origFileName2))
                    System.Diagnostics.Process.Start ( @origFileName2 ) ;
                else
                    System.Diagnostics.Process.Start ( @origFileName ) ;
            }   
            catch ( Exception ex ) 
            {
                MessageBox.Show( ex.Message + "Can't create a new document. The report may be open. Close it to create a new one.", Properties.Resources.AppName);
            }

ashukite
 
Posts: 1
Joined: Tue Sep 26, 2017 7:14 am

Mon Oct 23, 2017 6:49 am

Hi ashukite,

Thanks for your inquiry.
Which line will throw the exception ?
I first suggest you use the latest Spire.Doc Pack(hot fix) Version:6.0.31 if you were using older version. If the issue still exists, please provide us with the input document as well as the data you were using or a sample project for further testing.

Many thanks,
Betsy
E-iceblue support team
User avatar

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

Fri Dec 07, 2018 12:42 pm

Can somebody give me working XEvil captcha solver?
It is best captchas solver, including Google ReCaptcha.

Im so need it for my marketplace!
Already got key for XEvil:
3O1AllSstu5ZyPriRw_Mem

But dont know, how to use it.
Thank for everybody, and sorry for my english!

PM me if you know anything, I can pay.

XEvilBestMem
 
Posts: 1
Joined: Tue Nov 27, 2018 11:27 pm

Mon Dec 10, 2018 2:40 am

Hi,

This is E-iceblue!
Sorry that we are not familiar with XEvil, please contact XEvil for help.
If you need any assistance in regards to Spire products, just get it back to us.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Oct 07, 2019 7:44 am

HI,

I have the same issue. After several trys, I found out, that the error occurs when I am trying to clone a table from one word to another and to insert it in a certain DocumentObject position of the new document. I am able to clone everything and insert it into the new document, except the table.
The error occurs during the saving of the document. If I put in an if clause to ignore the tables, then it works fine.
If I just add it at the end, it works fine also for the table. But I have to insert the content of a document into a certain position of another document.
I am using Spire.Doc Version 7.9.9.

Code: Select all
foreach (Section sec in edtDoc.Sections)
{   
   foreach (DocumentObject obj in sec.Body.ChildObjects)
   {      
      targetSection.Body.ChildObjects.Insert(myindex + i, obj.Clone());
      i++;      
   }
}

MemoryStream upstreamDoc = new MemoryStream();
mydoc.SaveToStream(upstreamDoc, FileFormat.Docx);
currentWeb.Files.Add(currentWeb.Url + "/" + outputLibraryName + "/" + outputFileNameDoc, upstreamDoc, true);

MemoryStream upstreamPdf = new MemoryStream();
mydoc.SaveToStream(upstreamPdf, FileFormat.PDF);
currentWeb.Files.Add(currentWeb.Url + "/" + outputLibraryName + "/" + outputFileNamePdf, upstreamPdf, true);

bejdevatlonza
 
Posts: 2
Joined: Tue Sep 17, 2019 12:26 pm

Mon Oct 07, 2019 8:22 am

Hi Jens,

Thanks for your inquiry,
I simulated your scenario to have a test, but didn't encounter any issue when cloning tables. To help us further look into your issue, please provide your source and target Word documents, also provide the myindex you defined. You could attached your files here or send them to our email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Fri Oct 11, 2019 12:12 pm

Hi Nina,

thank's for your help. Attached the two files. I try to insert the content from source into target at the position marked with "Content of the source file should be inserted here".
As I wrote, it works fine as long as I do not try to insert a table. That does not work. I also tried only to insert a table with no success. Tables can only be added at the end of a section but not inserted at a certain position. But that is what I really need.

Thank's for any idea or help.

BR Jens

bejdevatlonza
 
Posts: 2
Joined: Tue Sep 17, 2019 12:26 pm

Sat Oct 12, 2019 8:19 am

Hi Jens,

Thanks for your files.
After testing your case with the latest Spire.Doc Pack(hot fix) Version:7.9.9, I didn't encounter any issue. The table could be inserted in correct position. Here is my full test code:
Code: Select all
            Document edtDoc = new Document(FilePath +"Example Source Doc.docx");
            Document target = new Document(FilePath + "Example Target Doc.docx");

            TextSelection selection1 = target.FindString("Content of the source file should be inserted", false, false);
            TextRange range1 = selection1.GetAsOneRange();
            Section targetSection = range1.OwnerParagraph.Owner.Owner as Section;
            int startIndex = targetSection.Body.ChildObjects.IndexOf(range1.OwnerParagraph);

            int i = 1;
            foreach (Section sec in edtDoc.Sections)
            {
                foreach (DocumentObject obj in sec.Body.ChildObjects)
                {
                    targetSection.Body.ChildObjects.Insert(startIndex + i, obj.Clone());
                    i++;
                }
            }

            target.SaveToFile("19122.docx", FileFormat.Docx);


And I attached my result file. If you still have the issue, please provide following information for further investigation:
1. The complete code.
2. The OS and Region information, e.g. Win7 64bit, China/Chinese.
3. The output you got.
4. The desired result.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue Oct 29, 2019 6:13 am

Hi,

Greetings from E-iceblue.
Has your issue been resolved? Could you please give us some feedback at your convenience?

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.Doc