Exemple #1
0
 void ProcessDataSets()
 {
     foreach (var dataSet in _dataSetRows)
     {
         IList <ExpandoObject> list = _dataModel.Eval <List <ExpandoObject> >(dataSet.Key);
         if (list == null)
         {
             throw new InteropException($"The data model does not have a '{dataSet.Key}' property ");
         }
         RowSetDef def = dataSet.Value;
         if (list.Count == 0)
         {
             // no records - delete range
             for (Int32 i = 0; i < def.RowCount; i++)
             {
                 var row = _sheetData.Elements <Row>().First <Row>(r => r.RowIndex == def.FirstRow + i);
                 row.Remove();
             }
             _wrkshtModified = true;
         }
         else
         {
             UInt32 count = 0;
             Row    lr    = null;
             for (Int32 i = 0; i < list.Count; i++)
             {
                 lr = InsertRowFromTemplate(def, ref count);
                 _wrkshtModified = true;
                 SetRecordData(def, list[i]);
             }
         }
     }
 }
Exemple #2
0
 void SetRecordData(RowSetDef def, ExpandoObject data)
 {
     // Пока просто индекс
     foreach (var r in def.Rows)
     {
         foreach (var c in r.Elements <Cell>())
         {
             SetCellData(c, data);
         }
     }
 }
Exemple #3
0
 void SetRecordData(RowSetDef def, ExpandoObject data)
 {
     // just an index (for now)
     foreach (var r in def.Rows)
     {
         foreach (var c in r.Elements <Cell>())
         {
             SetCellData(c, data);
         }
     }
 }
Exemple #4
0
 void ProcessDataSets()
 {
     foreach (var dataSet in _dataSetRows)
     {
         IList <ExpandoObject> list = _dataModel.Eval <List <ExpandoObject> >(dataSet.Key);
         if (list == null)
         {
             throw new InteropException($"The data model does not have a '{dataSet.Key}' property ");
         }
         RowSetDef def   = dataSet.Value;
         UInt32    count = 0;
         Row       lr    = null;
         for (Int32 i = 0; i < list.Count; i++)
         {
             lr = InsertRowFromTemplate(def, ref count);
             _wrkshtModified = true;
             SetRecordData(def, list[i]);
         }
     }
 }
Exemple #5
0
        Row InsertRowFromTemplate(RowSetDef rd, ref UInt32 count)
        {
            Row lastRow = null;

            if (rd.Rows == null)
            {
                // строки еще нет, нужно ее найти
                var row = _sheetData.Elements <Row>().First <Row>(r => r.RowIndex == rd.FirstRow);
                rd.Rows         = new List <Row>();
                rd.RowsForClone = new List <Row>();
                for (Int32 i = 0; i < rd.RowCount; i++)
                {
                    rd.Rows.Add(row);
                    rd.RowsForClone.Add(row.Clone() as Row);                     // и для клонирования тоже!
                    row     = row.NextSibling <Row>();
                    lastRow = row;
                }
            }
            else
            {
                // Строка уже была, нужно ее клонировать и вставить ниже
                lastRow = rd.Rows[rd.Rows.Count - 1];
                // индекс следующей вставляемой строки
                UInt32 nri = rd.Rows[0].RowIndex.Value + rd.RowCount;
                for (Int32 i = 0; i < rd.Rows.Count; i++)
                {
                    var sr = rd.RowsForClone[i];
                    var nr = sr.Clone() as Row;
                    nr.RowIndex = nri++;
                    CorrectCellAddresses(nr);
                    _sheetData.InsertAfter <Row>(nr, lastRow);
                    count++;                     // вставили строку
                    rd.Rows[i] = nr;             // Для следующей вставки делаем
                    lastRow    = nr;             // последняя уже вставлена
                }
            }
            return(lastRow);
        }
Exemple #6
0
        Row InsertRowFromTemplate(RowSetDef rd, ref UInt32 count)
        {
            Row lastRow = null;

            if (rd.Rows == null)
            {
                // строки еще нет, нужно ее найти
                var row = _sheetData.Elements <Row>().First <Row>(r => r.RowIndex == rd.FirstRow);
                rd.Rows         = new List <Row>();
                rd.RowsForClone = new List <Row>();
                for (Int32 i = 0; i < rd.RowCount; i++)
                {
                    rd.Rows.Add(row);
                    rd.RowsForClone.Add(row.Clone() as Row);                     // and for cloning too!
                    row     = row.NextSibling <Row>();
                    lastRow = row;
                }
            }
            else
            {
                // The line was already there, you need to clone it and insert it below
                lastRow = rd.Rows[rd.Rows.Count - 1];
                // next row index
                UInt32 nri = rd.Rows[0].RowIndex.Value + rd.RowCount;
                for (Int32 i = 0; i < rd.Rows.Count; i++)
                {
                    var sr = rd.RowsForClone[i];
                    var nr = sr.Clone() as Row;
                    nr.RowIndex = nri++;
                    CorrectCellAddresses(nr);
                    _sheetData.InsertAfter <Row>(nr, lastRow);
                    count++;
                    rd.Rows[i] = nr;
                    lastRow    = nr;                  // the last one is already inserted
                }
            }
            return(lastRow);
        }
Exemple #7
0
        void CheckDefinedName(DefinedName dn)
        {
            String name = dn.Name;

            if (!name.StartsWith("_") || !name.EndsWith("_"))
            {
                return;
            }
            String propName = name.Substring(1, name.Length - 2);
            String showRef  = dn.Text;
            Int32  exclPos  = showRef.IndexOf('!');

            if (exclPos == -1)
            {
                return;
            }
            String shtName  = showRef.Substring(0, exclPos);
            String shtRef   = showRef.Substring(exclPos + 1);
            Int32  colonPos = shtRef.IndexOf(':');

            if (colonPos == -1)
            {
                return;
            }
            String startRef = shtRef.Substring(0, colonPos);             // ссылка на первую строку дипазона
            String endRef   = shtRef.Substring(colonPos + 1);            // ссылка на вторую строку диапазона

            if (startRef.Length < 2)
            {
                return;
            }
            if (endRef.Length < 2)
            {
                return;
            }
            UInt32 startRow = 0;
            UInt32 endRow   = 0;

            if (startRef[0] == '$')
            {
                if (!UInt32.TryParse(startRef.Substring(1), out startRow))
                {
                    return;
                }
            }
            if (endRef[0] == '$')
            {
                if (!UInt32.TryParse(endRef.Substring(1), out endRow))
                {
                    return;
                }
            }
            if (_dataSetRows == null)
            {
                _dataSetRows = new Dictionary <String, RowSetDef>();
            }
            RowSetDef rd = new RowSetDef
            {
                FirstRow = startRow,
                RowCount = endRow - startRow + 1
            };

            _dataSetRows.Add(propName, rd);
        }