Esempio n. 1
0
        public Word ExportFromTemplate <T>(string templateUrl, T wordData) where T : class, new()
        {
            XWPFDocument word = NPOIHelper.GetXWPFDocument(templateUrl);

            ReplacePlaceholders(word, wordData);

            var result = new Word()
            {
                Type      = SolutionEnum.NPOI,
                WordBytes = word.ToBytes()
            };

            return(result);
        }
Esempio n. 2
0
        public IEnumerable <Table> GetTables(string fileUrl)
        {
            var result = new List <Table>();

            var doc = NPOIHelper.GetXWPFDocument(fileUrl);

            var xwpfParagraphsEnumerator = doc.GetParagraphsEnumerator();

            while (xwpfParagraphsEnumerator.MoveNext())
            {
                var xwpfParagraph = xwpfParagraphsEnumerator.Current;
            }

            return(result);
        }
Esempio n. 3
0
        public Word CreateFromMasterTable <T>(string templateUrl, IEnumerable <T> datas) where T : class, new()
        {
            var template = NPOIHelper.GetXWPFDocument(templateUrl);

            var result = new Word()
            {
                Type = SolutionEnum.NPOI
            };

            var tables = template.GetTablesEnumerator();

            if (tables == null)
            {
                result.WordBytes = template.ToBytes();
                return(result);
            }

            var masterTables = new List <XWPFTable>();

            while (tables.MoveNext())
            {
                masterTables.Add(tables.Current);
            }

            var doc = new XWPFDocument();

            foreach (var data in datas)
            {
                foreach (var masterTable in masterTables)
                {
                    var cloneTable = doc.CreateTable();
                    NPOIHelper.CopyTable(masterTable, cloneTable);
                }

                ReplacePlaceholders(doc, data);
            }

            result.WordBytes = doc.ToBytes();

            return(result);
        }