Exemplo n.º 1
0
        private void ParseTableDefinition(ExecuteArgs param, Dictionary <string, DefinedName> cacheNames, Stream tableDefinitionPart, TableDefinitionPart newTableDefinitionPart)
        {
            using (var reader = OpenXmlReader.Create(tableDefinitionPart))
                using (var writer = XmlWriter.Create(newTableDefinitionPart.GetStream(),
                                                     new XmlWriterSettings {
                    Encoding = Encoding.UTF8, CloseOutput = true
                }))
                {
                    writer.WriteStartDocument(true);
                    while (reader.Read())
                    {
                        if (reader.ElementType == typeof(Excel.Table))
                        {
                            var table = (Excel.Table)reader.LoadCurrentElement();

                            var code = param.ParseCode(table.Name);
                            if (code != null)
                            {
                                var reference = CellRange.Parse(table.Reference.Value);
                                var defName   = new DefinedName
                                {
                                    Name       = table.Name,
                                    Range      = reference,
                                    Code       = code,
                                    CacheValue = param.GetValue(code)
                                };
                                if (defName.CacheValue is QResult result && result.Values.Count > 0)
                                {
                                    var index = reference.Start.Row + result.Values.Count;
                                    if (index > reference.End.Row)
                                    {
                                        defName.NewRange = new CellRange(reference.Start, new CellReference(reference.End.Col, index));
                                        table.Reference  = defName.NewRange.ToString();
                                        //table.TotalsRowCount = (uint)newrange.Rows;
                                    }
                                    defName.Table = table;
                                    cacheNames[defName.Range.Start.ToString()] = defName;
                                }
                            }
                            WriteElement(writer, table);
                        }
                        else if (reader.IsStartElement)
                        {
                            WriteStartElement(writer, reader);
                        }
                        else if (reader.IsEndElement)
                        {
                            writer.WriteEndElement();
                        }
                    }
                    writer.WriteEndDocument();
                    writer.Flush();
                }
        }
Exemplo n.º 2
0
 private void ParseWorkbookPart(ExecuteArgs param, Dictionary <string, Dictionary <string, DefinedName> > cacheNames, Stream workbookPart, WorkbookPart newWorkbookPart, List <Excel.Sheet> sheetList)
 {
     using (var reader = OpenXmlReader.Create(workbookPart))
         using (var writer = XmlWriter.Create(newWorkbookPart.GetStream(),
                                              new XmlWriterSettings {
             Encoding = Encoding.UTF8, CloseOutput = true
         }))
         {
             writer.WriteStartDocument(true);
             while (reader.Read())
             {
                 //if (reader.ElementType == typeof(AlternateContent))
                 //{
                 //    var alternate = (AlternateContent)reader.LoadCurrentElement();
                 //    continue;
                 //}
                 if (reader.ElementType == typeof(Excel.DefinedName))
                 {
                     var name = (Excel.DefinedName)reader.LoadCurrentElement();
                     if (!string.IsNullOrEmpty(name.InnerText))
                     {
                         var split = name.InnerText.Split('!');
                         if (split.Length == 2)
                         {
                             var sheet = split[0].Trim('\'');
                             var code  = param.ParseCode(name.Name);
                             if (code != null)
                             {
                                 if (!cacheNames.TryGetValue(sheet, out var names))
                                 {
                                     cacheNames[sheet] = names = new Dictionary <string, DefinedName>();
                                 }
                                 var defName = new DefinedName
                                 {
                                     Name      = name.Name,
                                     Sheet     = sheet,
                                     Reference = split[1],
                                     Code      = code
                                 };
                                 names.Add(defName.Range.Start.ToString(), defName);
                             }
                         }
                     }
                     WriteElement(writer, name);
                 }
                 else if (reader.ElementType == typeof(Excel.Sheet))
                 {
                     var sheet = (Excel.Sheet)reader.LoadCurrentElement();
                     sheetList.Add(sheet);
                     WriteElement(writer, sheet);
                 }
                 else if (reader.IsStartElement)
                 {
                     WriteStartElement(writer, reader);
                 }
                 else if (reader.IsEndElement)
                 {
                     writer.WriteEndElement();
                 }
             }
             writer.WriteEndDocument();
             writer.Flush();
         }
 }
Exemplo n.º 3
0
        public object ParseString(ExecuteArgs parameters, string code)
        {
            var    temp = code.Split(new char[] { ':' });
            object val  = null;

            string procedureCode = code;
            string param         = null;
            string localize      = null;

            if (temp.Length > 0)
            {
                string type = temp[0].Trim();
                if (type.Equals("c", StringComparison.OrdinalIgnoreCase))
                {
                    string[] vsplit = temp[1].Split(new char[] { ' ' });
                    string   column = vsplit[0].Trim();
                    val = parameters.Document[column];
                    if (temp.Length > 2)
                    {
                        param = temp[2].Trim();
                    }
                    if (temp.Length > 3)
                    {
                        localize = temp[3];
                    }
                }
                else if (type.Equals("p", StringComparison.OrdinalIgnoreCase))
                {
                    procedureCode = temp[1].Trim();
                }
                else if (parameters.Parameters.TryGetValue(type, out val))
                {
                    if (temp.Length > 1)
                    {
                        param = temp[1].Trim();
                    }
                    if (temp.Length > 2)
                    {
                        localize = temp[2];
                    }
                }
                else if (code == "list")
                {
                    val = parameters.Result;
                }
            }
            if (param != null && param.Length > 0)
            {
                CultureInfo culture = CultureInfo.InvariantCulture;
                if (localize != null)
                {
                    culture = CultureInfo.GetCultureInfo(localize);
                }
                val = Helper.TextDisplayFormat(val, param, culture);
            }

            if (val == null)
            {
                var codeAttribute = parameters.ParseCode(procedureCode);
                if (codeAttribute != null)
                {
                    val = parameters.GetValue(codeAttribute);
                }
                else
                {
                    var procedure = DBService.Schems.ParseProcedure(procedureCode, parameters.ProcedureCategory);
                    if (procedure != null)
                    {
                        try { val = procedure.Execute(parameters); }
                        catch (Exception ex) { val = ex.Message; }
                    }
                }
            }

            return(val);
        }