Ejemplo n.º 1
0
 private void ExpandSheet(ISheet sheet, DataRow mainRow)
 {
     for (int i = 0; i <= sheet.LastRowNum; i++)
     {
         for (int j = 0; j < sheet.GetRow(0).LastCellNum; j++)
         {
             NamedRange expandRegion = GetExpandRegion(sheet, i, j);
             if (expandRegion == null)
             {
                 ReplaceRange(sheet.GetRow(i).GetCell(j), mainRow, 1);
             }
             else
             {
                 int rowCount           = expandRegion.RowCount;
                 int colCount           = expandRegion.ColCount;
                 DataRowCollection rows = res.Data.Rows;
                 if (rows != null)
                 {
                     for (int k = 0; k < rows.Count; k++)
                     {
                         Range range = new Range(sheet, i, i + rowCount - 1, j, j + colCount - 1);
                         if (j == range.FirstCol && k + 1 < rows.Count)
                         {
                             sheet.ShiftRows(range.FirstRow, range.LastRow, rowCount, true, false);
                             for (int l = range.FirstRow; l <= range.LastRow; l++)
                             {
                                 sheet.CopyRow(l + rowCount, l);
                                 if (!autoHeight)
                                 {
                                     sheet.GetRow(l).Height = sheet.GetRow(l + rowCount).Height;
                                 }
                             }
                         }
                         ExpandRange(range, rows[k], k + 1);
                         i += rowCount;
                     }
                 }
                 else
                 {
                     ExpandRange(expandRegion, null, 1);
                 }
                 j += colCount - 1;
             }
         }
     }
 }
Ejemplo n.º 2
0
 private NamedRange GetExpandRegion(ISheet s, int r, int c)
 {
     for (int i = 0; i < Workbook.NumberOfNames; i++)
     {
         NamedRange namedRange = new NamedRange(Workbook, Workbook.GetNameAt(i));
         if (namedRange.Sheet == s &&
             namedRange.Name.NameName.StartsWith("expand_") &&
             namedRange.FirstRow <= r &&
             namedRange.FirstCol <= c &&
             namedRange.LastRow >= r &&
             namedRange.LastCol >= c)
         {
             return(namedRange);
         }
     }
     return(null);
 }