DocXWrite.cs

47 lines | 1.313 kB Blame History Raw Download
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//using OfficeOpenXml;
using Xceed.Words.NET;

namespace Tools.Word
{
    public class DocXWrite
    {
        public System.IO.Stream EntitysToDocx(IEnumerable<object> d)
        {
            return new System.IO.MemoryStream();
        }

        public static void Test(List<I_MySerializable> list, out System.IO.Stream wr, string path = "")
        {
            wr = new System.IO.MemoryStream();
            DocX doc = DocX.Create(wr);
            foreach (var elem in list)
                Serialize(elem, doc);
            if (path != "")
                doc.SaveAs(path);           
        }

        public static void Test(I_MySerializable elem, out System.IO.Stream wr, string path = "")
        {
            wr = new System.IO.MemoryStream();
            DocX doc = DocX.Create(wr);
            Serialize(elem, doc);
            if (path != "")
                doc.SaveAs(path);
        }

        private static void Serialize(I_MySerializable obj, DocX doc)
        {
            var serialize = obj.Serialize();
            foreach (var elem in serialize)
                if (elem.Value != null && elem.Value != "")
                    doc.InsertParagraph(elem.Key + " : " + elem.Value);
        }
    }
}