Here is the snippet.
- Code: Select all
const int size = 100;
string[] names = Enum.GetNames(typeof(Spire.Doc.Documents.BuiltinStyle));
int count = 0;
while (count < names.Length)
{
//Create New Word
using (var document = new Spire.Doc.Document())
{
//Add Section
Spire.Doc.Section section = document.AddSection();
//enumerate built-in styles
for (int n = 0; n < size; n++)
{
if (count + n >= names.Length) break;
var bs = (Spire.Doc.Documents.BuiltinStyle)Enum.Parse(
typeof(Spire.Doc.Documents.BuiltinStyle),
names[count + n]
);
Spire.Doc.Documents.Paragraph p = section.AddParagraph();
p.ApplyStyle(bs);
p.AppendText(names[count + n] + Environment.NewLine);
}
//Save Word
document.SaveToFile(
string.Format(@"C:\Users\Mario\Documents\BuiltInStyles_{0}.docx", count),
Spire.Doc.FileFormat.Docx
);
count += size;
}
}
Console.WriteLine("Complete.");
When I put the break to the "SaveToFile" method (so, *before* executing it), the only section shows exactly 100 paragraphs. However, the execution of the "SaveToFile" method throws an exception caused by the limitation overflow. By re-watching the section content, it appears that the paragraphs are doubled.
If I set the "size" const to 50, everything goes fine. If I set to 51, an exception is raised.
Where's the trick?