public void WriteToFile(string fileName, List<Problem> source, int numberOfPage)
        {
            DocX doc = DocX.Create(fileName);
              var font = new System.Drawing.FontFamily("Consolas");
              var rand = new Random(DateTime.Now.Millisecond);
              var gap = new string(' ', spaceBetweenProblem - 1);

              var totalCount = colCount * rowCount * numberOfPage;

              List<Problem> allItems = new List<Problem>();
              while (allItems.Count < totalCount)
              {
            var problems = source.ToArray();
            Utils.Shuffle(problems);
            allItems.AddRange(problems);
              }

              Paragraph lastLine = null;
              for (int page = 0; page < numberOfPage; page++)
              {
            var from = colCount * rowCount * page;

            for (int row = 0; row < rowCount; row++)
            {
              var line1 = doc.InsertParagraph();
              lastLine = doc.InsertParagraph();
              for (int col = 0; col < colCount; col++)
              {
            line1.Append(string.Format("{0} ", allItems[from].LeftNumber.ToString().PadLeft(maxDigits + 1, ' '))).Font(font).FontSize(fontSize).Append(gap).Font(font).FontSize(fontSize);
            lastLine.Append(string.Format("{0}{1} ", allItems[from].Sign, allItems[from].RightNumber.ToString().PadLeft(maxDigits, ' '))).Font(font).FontSize(fontSize).UnderlineStyle(UnderlineStyle.thick).Append(gap).Font(font).FontSize(fontSize);
            from++;
              }

              if (row != rowCount - 1)
              {
            for (int i = 0; i < spaceLinesBetweenItem; i++)
            {
              lastLine = doc.InsertParagraph();
            }
              }
            }

            if (page != numberOfPage - 1 && addPageBreak)
            {
              lastLine.InsertPageBreakAfterSelf();
            }
              }
              doc.Save();
        }
Beispiel #2
0
        public string[] ValidateBookmarks(params string[] bookmarkNames)
        {
            var headers = new[] {Document.Headers.first, Document.Headers.even, Document.Headers.odd}.Where(h => h != null).ToList();
            var footers = new[] {Document.Footers.first, Document.Footers.even, Document.Footers.odd}.Where(f => f != null).ToList();

            var nonMatching = new List<string>();
            foreach (var bookmarkName in bookmarkNames)
            {
                if (headers.SelectMany(h => h.Paragraphs).Any(p => p.ValidateBookmark(bookmarkName))) return new string[0];
                if (footers.SelectMany(h => h.Paragraphs).Any(p => p.ValidateBookmark(bookmarkName))) return new string[0];
                if (Paragraphs.Any(p => p.ValidateBookmark(bookmarkName))) return new string[0];
                nonMatching.Add(bookmarkName);
            }

            return nonMatching.ToArray();
        }
Beispiel #3
0
        public List InsertList(int index, List list)
        {
            Paragraph p = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            XElement[] split = HelperFunctions.SplitParagraph(p, index - p.startIndex);
            var elements = new List<XElement> { split[0] };
            elements.AddRange(list.Items.Select(i => new XElement(i.Xml)));
            elements.Add(split[1]);
            p.Xml.ReplaceWith(elements.ToArray());

            return list;
        }
Beispiel #4
0
 /// <summary> 
 /// Set Table column width by prescribing percent 
 /// </summary> 
 /// <param name="widthsPercentage">column width % list</param> 
 /// <param name="totalWidth">Total table width. Will be calculated if null sent.</param>
 public void SetWidthsPercentage(float[] widthsPercentage, float? totalWidth)
 {
     if (totalWidth == null) totalWidth = this.Document.PageWidth - this.Document.MarginLeft - this.Document.MarginRight; // calculate total table width
     List<float> widths = new List<float>(widthsPercentage.Length); // empty list, will hold actual width
     widthsPercentage.ToList().ForEach(pWidth => { widths.Add((pWidth * totalWidth.Value / 100) * (96 / 72)); }); // convert percentage to actual width for all values in array
     SetWidths(widths.ToArray()); // set actual column width
 }
Beispiel #5
0
 public Paragraph[] InsertParagraphs(string text)
 {
     String[] textArray = text.Split('\n');
     List<Paragraph> paragraphs = new List<Paragraph>();
     foreach (var textForParagraph in textArray)
     {
         Paragraph p = base.InsertParagraph(text);
         p.PackagePart = mainPart;
         paragraphs.Add(p);
     }
     return paragraphs.ToArray();
 }
Beispiel #6
0
 //获取文档中的所有表格,tables[i]
 public static Table[] getTables(DocX document)
 {
     List<Table> ts = new List<Table>();
     ts = null;
     ts = document.Tables;
     return ts.ToArray<Table>();
 }
Beispiel #7
0
 public static Res1[] Parse(XElement elnote)
 {
     List<Res1> al = new List<Res1>();
     foreach (var elres in elnote.Elements("resource")) {
         foreach (var eldata in elres.Elements("data")) {
             if (eldata.Attribute("encoding").Value == "base64") {
                 byte[] bin = Convert.FromBase64String(eldata.Value);
                 al.Add(new Res1 { si = new MemoryStream(bin, false), elres = elres, md5 = HUt.GetStr(MD5.Create().ComputeHash(bin)) });
             }
             break;
         }
     }
     return al.ToArray();
 }