예제 #1
0
 /// <summary>
 /// Reset enumerator, move to first entity
 /// </summary>
 public void Reset()
 {
     _currentIdx  = -1;
     _current     = null;
     _entityRange = null;
     _endBefore   = null;
     if (!String.IsNullOrEmpty(_colCfg.EndBefore))
     {   // There is abort flag cell, using defined name to mark cell dynamically.
         _endBefore = _doc.GetRange(_colCfg.EndBefore);
     }
 }
예제 #2
0
 /// <summary>
 /// Write one object to excel at current location and move to next location for next object
 /// </summary>
 /// <param name="obj"></param>
 public void Write(T obj)
 {
     // Calculate the entity range
     if (_entityRange == null)
     {     // No entity range calculated, this is the first entity
         if (_collectionRange == null)
         { // First time, calculate collection range
             if (_parentRange != null)
             {
                 _collectionRange = _parentRange.GetSubRange(_colCfg.Range);
             }
             else
             {
                 _collectionRange = _doc.GetRange(_colCfg.Range);
             }
             if (_collectionRange == null)
             {
                 throw new InvalidDataException(String.Format("Cannot find valid range for collection of {0}!",
                                                              typeof(T).FullName));
             }
         }
         EntityConfigElement entCfg = _colCfg.ItemTemplate.Entity;
         String entRef   = _collectionRange.Sheet.ExpandToSheetBound(entCfg.Range);
         String entRange = ExcelOpenXMLHelper.CalculateEntityRange(_collectionRange, entRef, 0,
                                                                   _colCfg.Orientation.Equals("vertical", StringComparison.OrdinalIgnoreCase));
         if (entRange == null)
         {
             throw new NoMoreEntityException(typeof(T));
         }
         _entityRange = _collectionRange.GetSubRange(entRange);
         if (_entityRange == null)
         {
             throw new NoMoreEntityException(typeof(T));
         }
     }
     // Write object to range
     _entityRange.WriteEntity(_colCfg.ItemTemplate.Entity, obj);
     // Move range to next
     if (_colCfg.Orientation.Equals("vertical", StringComparison.OrdinalIgnoreCase))
     {   // Move vertically
         int h = _entityRange.Height;
         _entityRange.Move(0, h);
     }
     else
     {   // Move horizontally
         int w = _entityRange.Width;
         _entityRange.Move(w, 0);
     }
 }