示例#1
0
 private void doPart(OpenXmlPart part, IDictionary <string, dynamic> stuffing)
 {
     try
     {
         XDocument xdoc1 = part.GetXDocument();
         foreach (KeyValuePair <string, dynamic> pair in stuffing)
         {
             XmlTemplateTool.ReplaceKey(xdoc1.Root, pair.Key, pair.Value);
         }
         part.PutXDocument(xdoc1);
     }
     catch (Exception ex) { Console.WriteLine("XmlFiller.Fill", "bad excel part", ex); }
 }
示例#2
0
 private void doPart(OpenXmlPart part, IDictionary <string, dynamic> stuffing)
 {
     try
     {
         XDocument xdoc1 = part.GetXDocument();
         foreach (KeyValuePair <string, dynamic> pair in stuffing)
         {
             XmlTemplateTool.ReplaceKey(xdoc1.Root, pair.Key, pair.Value);
         }
         part.PutXDocument(xdoc1);
     }
     catch (Exception ex)
     {
         //System.Diagnostics.Trace.TraceError("XmlFiller.Fill bad excel part {0}", ex);
     }
 }
示例#3
0
        public async Task <bool> FillAsync(ITemplate t, IDictionary <string, dynamic> stuffing, Stream output)
        {
            // TODO: make this more asyncy
            XmlWriter writer = XmlWriter.Create(output, new XmlWriterSettings()
            {
                Encoding = UTF8Encoding.UTF8, Indent = true, Async = true
            });

            // should only be one section
            foreach (var section in t.SectionNames)
            {
                XDocument doc;
                try { doc = XDocument.Parse(t.GetSectionText(section)); }
                catch (Exception) { continue; }
                foreach (KeyValuePair <string, dynamic> pair in stuffing)
                {
                    XmlTemplateTool.ReplaceKey(doc.Root, pair.Key, pair.Value);
                }
                doc.WriteTo(writer);
            }
            await writer.FlushAsync();

            return(true);
        }