Ejemplo n.º 1
0
 public CommonWorkSheet GetTemplateSheet(MemoryStream templateFile)
 {
     try
     {
         var sheet            = new CommonWorkSheet();
         var templateWorkPart = SpreadsheetDocument.Open(templateFile, false).WorkbookPart;
         sheet.Sheet = templateWorkPart.WorksheetParts.First().Worksheet;
         #region build defined names
         sheet.DefinedNames = BuildDefinedNamesTable(templateWorkPart, 0);
         #endregion
         return(sheet);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
 private void FillObject <T>(T container, WorkbookPart workbookPart, CommonWorkSheet templateSheet) where T : class, new()
 {
     #region Fill Single cell
     foreach (var item in templateSheet.DefinedNames.Where(n => !n.IsRange))
     {
         SetObjValue <T>(container, item, workbookPart);
     }
     #endregion
     #region Fill Range cells
     foreach (var item in templateSheet.DefinedNames.Where(n => n.IsRange))
     {
         var startRow = item.StartRow;
         var count    = FillRangeObjs(container, item, workbookPart);
         if (count > 0)
         {
             foreach (var c in templateSheet.DefinedNames.Where(n => Convert.ToInt32(n.StartRow) > Convert.ToInt32(startRow)))
             {
                 c.ShiftRows(count);
             }
         }
     }
     #endregion
 }