コード例 #1
0
ファイル: AsciiReader.cs プロジェクト: payamad/Core
 /// <summary>
 /// Convert a list of variable names to
 /// VariableIdentifiers
 /// </summary>
 /// <seealso cref="VariableIdentifier"/>
 /// <param name="variablesRow"></param>
 private void convertAndAddToSubmitedVariableIdentifier()
 {
     if (VariableIdentifierRows != null)
     {
         foreach (List <string> l in VariableIdentifierRows)
         {
             //create headerVariables
             if (SubmitedVariableIdentifiers.Count == 0)
             {
                 foreach (string s in l)
                 {
                     VariableIdentifier hv = new VariableIdentifier();
                     hv.name = s;
                     SubmitedVariableIdentifiers.Add(hv);
                 }
             }
             else
             {
                 foreach (string s in l)
                 {
                     int id    = Convert.ToInt32(s);
                     int index = l.IndexOf(s);
                     SubmitedVariableIdentifiers.ElementAt(index).id = id;
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: ExcelReader.cs プロジェクト: payamad/Core
        /// <summary>
        /// Generate a list of VariableIdentifiers from the excel file
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="worksheetPart">part of a excel worksheet</param>
        /// <param name="startRow">start row</param>
        /// <param name="endRow">end row</param>
        /// <returns>List of variableIdentifier</returns>
        protected List <VariableIdentifier> GetSubmitedVariableIdentifier(WorksheetPart worksheetPart, int startRow, int endRow)
        {
            //NEW OPENXMLREADER
            if (this.SubmitedVariableIdentifiers == null || this.SubmitedVariableIdentifiers.Count == 0)
            {
                OpenXmlReader reader = OpenXmlReader.Create(worksheetPart);
                int           rowNum = 0;

                // read variable rows to get name and id from area variable
                while (reader.Read())
                {
                    if (reader.ElementType == typeof(Row))
                    {
                        do
                        {
                            if (reader.HasAttributes)
                            {
                                rowNum = Convert.ToInt32(reader.Attributes.First(a => a.LocalName == "r").Value);
                            }

                            if (rowNum >= startRow && rowNum <= endRow)
                            {
                                Row row = (Row)reader.LoadCurrentElement();

                                if (row.Hidden == null)
                                {
                                    VariableIdentifierRows.Add(RowToList(row));
                                }
                                else if (row.Hidden != true)
                                {
                                    VariableIdentifierRows.Add(RowToList(row));
                                }
                            }
                        } while (reader.ReadNextSibling() && rowNum < endRow); // Skip to the next row
                        break;
                    }
                }

                // convert variable rows to VariableIdentifiers
                if (VariableIdentifierRows != null)
                {
                    foreach (List <string> l in VariableIdentifierRows)
                    {
                        //create headerVariables
                        if (SubmitedVariableIdentifiers.Count == 0)
                        {
                            foreach (string s in l)
                            {
                                VariableIdentifier hv = new VariableIdentifier();
                                hv.name = s;
                                SubmitedVariableIdentifiers.Add(hv);
                            }
                        }
                        else
                        {
                            foreach (string s in l)
                            {
                                if (!string.IsNullOrEmpty(s))
                                {
                                    int id = 0;
                                    if (int.TryParse(s, out id))
                                    {
                                        int index = l.IndexOf(s);
                                        SubmitedVariableIdentifiers.ElementAt(index).id = id;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (this.SubmitedVariableIdentifiers != null)
            {
                return(this.SubmitedVariableIdentifiers);
            }
            else
            {
                return(null);
            }
        }