public void AppendErrorRows(string sheetName, IWorksheetWriter worksheetWriter)
 {
     if (worksheetWriter == null)
     {
         throw new ArgumentNullException("worksheetWriter");
     }
     if (FileContentStream == null)
     {
         throw new InvalidOperationException(string.Format("Cannot {0} prior to initializing from a template.", MethodBase.GetCurrentMethod().Name));
     }
     using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(FileContentStream, true))
     {
         //Access the main Workbook part, which contains data
         WorkbookPart workbookPart = spreadsheetDoc.WorkbookPart;
         Sheet ss = ExcelUtility.FindSheet(sheetName, workbookPart);
         if (ss == null)
         {
             throw new InvalidOperationException("Cannot find sheet named '" + sheetName + "' in workbook.");
         }
         WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(ss.Id);
         if (worksheetPart != null)
         {
             worksheetWriter.CreateErrorRows(worksheetPart);
             worksheetPart.Worksheet.Save();
         }
     }
 }
Exemplo n.º 2
0
 public void AppendErrorRows(string sheetName, IWorksheetWriter worksheetWriter)
 {
     if (worksheetWriter == null)
     {
         throw new ArgumentNullException("worksheetWriter");
     }
     if (FileContentStream == null)
     {
         throw new InvalidOperationException(string.Format("Cannot {0} prior to initializing from a template.", MethodBase.GetCurrentMethod().Name));
     }
     using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(FileContentStream, true))
     {
         //Access the main Workbook part, which contains data
         WorkbookPart workbookPart = spreadsheetDoc.WorkbookPart;
         Sheet        ss           = ExcelUtility.FindSheet(sheetName, workbookPart);
         if (ss == null)
         {
             throw new InvalidOperationException("Cannot find sheet named '" + sheetName + "' in workbook.");
         }
         WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(ss.Id);
         if (worksheetPart != null)
         {
             worksheetWriter.CreateErrorRows(worksheetPart);
             worksheetPart.Worksheet.Save();
         }
     }
 }