Inheritance: AbstractXmlBasedTemplate
Esempio n. 1
0
        public override IDocument Render(IDictionary<string, object> context)
        {
            Debug.Assert(context != null);
            Debug.Assert(this.engine != null);

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            //执行主要内容的渲染过程
            using (var inStream = new MemoryStream(base.GetBuffer(), false))
            using (var reader = new StreamReader(inStream, Encoding.UTF8))
            using (var ws = new MemoryStream())
            using (var writer = new StreamWriter(ws))
            {
                //执行渲染
                this.engine.Evaluate(context, reader, writer);
                writer.Flush();
                ws.Flush();
                var resultDoc = new ExcelMLTemplate();
                resultDoc.PutBuffer(ws.ToArray());
                return resultDoc;
            }
        }
Esempio n. 2
0
        internal void LoadFromDocument(ExcelMLTemplate doc)
        {
            Debug.Assert(doc != null);

            var buf = doc.GetBuffer();
            var newBuf = new byte[buf.Length];
            Buffer.BlockCopy(buf, 0, newBuf, 0, buf.Length);
            this.PutBuffer(newBuf);
        }
Esempio n. 3
0
        public static void Compile(ExcelMLTemplate doc)
        {
            if (doc == null)
            {
                throw new ArgumentNullException("template");
            }

            var xml = doc.GetXmlDocument();

            var nsmanager = new ExcelMLNamespaceManager(xml.NameTable);
            nsmanager.LoadOpenDocumentNamespaces();

            ClearTemplate(xml);

            ProcessPlaceHolders(xml);

            WriteCompiledMainContent(doc, xml);
        }
Esempio n. 4
0
        private static void WriteCompiledMainContent(ExcelMLTemplate t, XmlDocument xml)
        {
            Debug.Assert(t != null);
            Debug.Assert(xml != null);

            using (var ms = new MemoryStream())
            using (var writer = new ExcelMLTextWriter(ms))
            {
                writer.Formatting = Formatting.None; //对于 Velocity 模板,最好格式化
                xml.WriteTo(writer);
                writer.Flush();
                ms.Flush();
                t.PutBuffer(ms.ToArray());
            }
        }