示例#1
0
        private void SetStringByIndex(string excelRangeName,
                                      WorkbookDataFileWrapper.enWorkbookDataFileHelperItemType itemType,
                                      string value)
        {
            if (m_DataFileWrapper == null)
            {
                throw new InvalidOperationException("m_DataFileWrapper should not be null");
            }
            if (m_wshSetup == null)
            {
                throw new InvalidOperationException("m_wshSetup should not be null");
            }

            if (value == null)
            {
                m_wshSetup.Range[excelRangeName].Value = null;
            }
            else
            {
                var stringsInFile = m_DataFileWrapper.GetStrings(itemType);
                int index         = stringsInFile.IndexOf(value);
                if (index < 0)
                {
                    m_DataFileWrapper.AddItemIfNotExists(value, itemType);
                    index = stringsInFile.Count;
                }
                m_wshSetup.Range[excelRangeName].Value = index;
            }
        }
示例#2
0
        private string GetStringByIndex(string excelRangeName,
                                        WorkbookDataFileWrapper.enWorkbookDataFileHelperItemType itemType)
        {
            if (m_DataFileWrapper == null)
            {
                throw new InvalidOperationException("m_DataFileWrapper should not be null");
            }
            if (m_wshSetup == null)
            {
                throw new InvalidOperationException("m_wshSetup should not be null");
            }

            string res      = null;
            string indexRaw = m_wshSetup.Range[excelRangeName].Value?.ToString();
            int    index    = -1;

            if (!string.IsNullOrEmpty(indexRaw) &&
                int.TryParse(indexRaw, out index))
            {
                var stringsInFile = m_DataFileWrapper.GetStrings(itemType);
                if (index < stringsInFile.Count && index >= 0)
                {
                    res = stringsInFile[index];
                }
            }

            return(res);
        }