コード例 #1
0
        /// <summary>
        /// Initializes the StorageInfo.FieldNames
        /// </summary>
        public void ParseDataSourceFieldNames()
        {
            m_storageInfo.PossibleFieldNames = new List <string>();
            StorageInfo.FieldNames           = new List <SourceField>();
            // The Complete range of the MHT file
            Range documentRange = m_document.Range(Type.Missing, Type.Missing);

            foreach (Paragraph paragraph in documentRange.Paragraphs)
            {
                if (paragraph.Range.Tables.Count > 0 || paragraph.Range.InlineShapes.Count > 0)
                {
                    continue;
                }
                string field = CleanString(paragraph.Range.Text);
                if (!string.IsNullOrEmpty(field) && (paragraph.get_Style() as Style).NameLocal.Contains("Heading"))
                {
                    SourceField sourceField = new SourceField(field, false);
                    StorageInfo.FieldNames.Add(sourceField);
                }
                string styleName = (paragraph.get_Style() as Style).NameLocal;
                if (!string.IsNullOrEmpty(field) &&
                    (styleName.Contains("Heading") ||
                     styleName.Contains("Normal") ||
                     styleName.Contains("Comment")))
                {
                    m_storageInfo.PossibleFieldNames.Add(field);
                }
            }
        }
 private void DeleteFieldNameButton_Click(object sender, RoutedEventArgs e)
 {
     Button button = sender as Button;
     if (button != null && button.DataContext != null)
     {
         SourceField field = (SourceField)button.DataContext;
         m_part.Fields.Remove(field);
     }
 }
コード例 #3
0
ファイル: ExcelParser.cs プロジェクト: ahmedsza/tcmimport
        /// <summary>
        /// Parses the Data Source For Field Names
        /// </summary>
        public void ParseDataSourceFieldNames()
        {
            try
            {
                // If HeadersToColumn Is Not Empty the we redundantly calling this method
                if (m_headersToColumn.Count > 0)
                {
                    return;
                }

                m_storageInfo.FieldNames = new List <SourceField>();

                // Gets the worksheet containg the workitems
                Worksheet workSheet = (Worksheet)m_workBook.Worksheets[m_storageInfo.WorkSheetName];

                // Gets the last Row containg data in the Excel Data Source Sheet
                Missing missing = Missing.Value;
                Range   range   = workSheet.Cells.Find("*", missing, missing, missing, XlSearchOrder.xlByRows, XlSearchDirection.xlPrevious, false, missing, missing);

                // This sheet does not contain any data so returns null
                if (range == null)
                {
                    return;
                }

                m_lastRow = range.Row;

                // Gets the header row number from the Data Store
                if (!int.TryParse(m_storageInfo.RowContainingFieldNames, out m_headerRow) || m_headerRow < 0)
                {
                    throw new WorkItemMigratorException("Incorrect Header Row", null, null);
                }

                m_currentRow = m_headerRow;
                var headers = m_storageInfo.FieldNames;

                // Getting the Excel Range that contains the Row having Excel Field names
                Range row = workSheet.Rows[m_headerRow] as Range;

                // getting Values present in that row as an array of values
                Array array = row.Value2 as Array;

                int currentColumn = 1;

                // Parsing through each value in that array and filling headers and header to column mapping
                foreach (object o in array)
                {
                    // Only fills the data structures if the value is not null
                    if (o != null)
                    {
                        // getting Field Name
                        string header = o.ToString().Trim();

                        // update the datastructure is the value is not null or empty
                        if (!string.IsNullOrEmpty(header))
                        {
                            // Add Field Name in Headers
                            SourceField field = new SourceField(o.ToString().Trim(), false);
                            headers.Add(field);

                            // Update the Header to column Mapping
                            m_headersToColumn[header] = currentColumn;
                        }
                    }

                    // Done with current column. increment it to parse next cell in the row.
                    currentColumn++;
                }
            }
            catch (COMException)
            {
                // This may be due to the corrupted excel file format
                throw new WorkItemMigratorException("Field names are not found",
                                                    Resources.DataSourceFieldNamesNotFoundErrorLikelyCause,
                                                    Resources.DataSourceFieldNamesNotFoundErrorPotentialSolution);
            }
        }