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.

Wed May 25, 2016 9:41 pm

Hi,
I'm getting an ArgumentOutOfRangeException(Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) exception when saving a document to PDF. It appears to be related to merged cells but it doesn't happen in all cases of merged cells.
The below code will reproduce the problem:
Code: Select all
using (Document doc = new Document())
      {
        Section section = doc.AddSection();
        Table table = section.AddTable(true);
        table.ResetCells(2, 3);
        table.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
        table.TableFormat.LayoutType = LayoutType.Fixed;
        TableRow row = table.Rows[0];
        row.Cells[0].AddParagraph().AppendText("0:0");
        row.Cells[0].SetCellWidth(100, CellWidthType.Percentage);
        table.ApplyHorizontalMerge(0, 0, 2);
        row = table.Rows[1];
        row.Cells[0].AddParagraph().AppendText("1:0");
        row.Cells[0].SetCellWidth(50, CellWidthType.Percentage);
        row.Cells[1].AddParagraph().AppendText("1:1");
        row.Cells[1].SetCellWidth(25, CellWidthType.Percentage);
        row.Cells[2].AddParagraph().AppendText("1:2");
        row.Cells[2].SetCellWidth(25, CellWidthType.Percentage);
        string filename = Path.Combine(Path.GetTempPath(), "PdfTest.docx");
        doc.SaveToFile(filename, FileFormat.Docx2013);
        using (Process process = new Process())
        {
          process.StartInfo.FileName = filename;
          process.Start();
        }
        filename = Path.ChangeExtension(filename, ".pdf");
        doc.SaveToFile(filename, FileFormat.PDF);
        using (Process process = new Process())
        {
          process.StartInfo.FileName = filename;
          process.Start();
        }
      }


If I only have two columns in the table there is no error:
Code: Select all
using (Document doc = new Document())
      {
        Section section = doc.AddSection();
        Table table = section.AddTable(true);
        table.ResetCells(2, 2);
        table.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
        table.TableFormat.LayoutType = LayoutType.Fixed;
        TableRow row = table.Rows[0];
        row.Cells[0].AddParagraph().AppendText("0:0");
        row.Cells[0].SetCellWidth(100, CellWidthType.Percentage);
        table.ApplyHorizontalMerge(0, 0, 1);
        row = table.Rows[1];
        row.Cells[0].AddParagraph().AppendText("1:0");
        row.Cells[0].SetCellWidth(50, CellWidthType.Percentage);
        row.Cells[1].AddParagraph().AppendText("1:1");
        row.Cells[1].SetCellWidth(50, CellWidthType.Percentage);
        string filename = Path.Combine(Path.GetTempPath(), "PdfTest.docx");
        doc.SaveToFile(filename, FileFormat.Docx2013);
        using (Process process = new Process())
        {
          process.StartInfo.FileName = filename;
          process.Start();
        }
        filename = Path.ChangeExtension(filename, ".pdf");
        doc.SaveToFile(filename, FileFormat.PDF);
        using (Process process = new Process())
        {
          process.StartInfo.FileName = filename;
          process.Start();
        }
      }


Thanks,
Mark

markeye3
 
Posts: 27
Joined: Wed Jul 29, 2015 5:59 pm

Thu May 26, 2016 2:20 am

Hello Mark,

Thanks for your feedback.
I have noticed your issue and forwarded it to our dev team. Sorry for the inconvenience that the issue brought to you.
We will inform you once it is resolved.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Fri Jun 17, 2016 7:30 am

Hello Mark,

Thank you for your waiting.
The issue has been resolved, please download and test the new version Spire.Office Platinum (Hot Fix) Version:2.14.1.

Sincerely,
Caroline
E-iceblue support team
User avatar

caroline.zhang
 
Posts: 291
Joined: Mon Mar 07, 2016 9:22 am

Fri Jun 17, 2016 2:51 pm

Thanks Caroline, it appears to be working with the update.

markeye3
 
Posts: 27
Joined: Wed Jul 29, 2015 5:59 pm

Mon Jun 20, 2016 1:50 am

Hi,

Glad to hear that it works.
Welcome to feel free to write to us again if you have further problems.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc