public void GivenWorksheet_WhenCreateHeader_ThenCorrectHeaderCreated()
        {
            byte[]        byteArray = File.ReadAllBytes(Path.GetFullPath(ConfigurationManager.AppSettings["FileUploadTemplatePath"] + "Templates/" + ServiceOfferingController.TemplateFile));
            MemoryStream  stream    = new MemoryStream(byteArray);
            WorksheetPart actual;

            using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
            {
                actual = ExcelUtility.GetWorksheetPartByName(spreadsheetDoc, Target.SheetName);
                Target.CreateHeader(actual);
            }

            Assert.AreEqual(GetCell(actual.Worksheet, "B", 2).CellValue.InnerText, ServiceOffering.Id.ToString());
            Assert.AreEqual(GetCell(actual.Worksheet, "C", 2).CellValue.InnerText, ServiceOffering.Name);
        }
        public void GivenWorksheetWithFourColumns_WhenCreateErrorRows_ThenCorrectRowsAreCreated()
        {
            byte[]        byteArray = File.ReadAllBytes(Path.GetFullPath(ConfigurationManager.AppSettings["FileUploadTemplatePath"] + "Templates/" + ServiceOfferingController.TemplateFile));
            MemoryStream  stream    = new MemoryStream(byteArray);
            WorksheetPart actual;

            using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
            {
                actual = ExcelUtility.GetWorksheetPartByName(spreadsheetDoc, Target.SheetName);
                Target.ErrorRows.Add(new FileRowModel {
                    RowErrors = new List <string> {
                        "1", "1/1/1900", "1/1/1999", "Notes"
                    }
                });
                Target.CreateErrorRows(actual);
            }
            Assert.AreEqual(GetCell(actual.Worksheet, "B", 4).CellValue.InnerText, "1");
            Assert.AreEqual(GetCell(actual.Worksheet, "C", 4).CellValue.InnerText, "1/1/1900");
            Assert.AreEqual(GetCell(actual.Worksheet, "D", 4).CellValue.InnerText, "1/1/1999");
            Assert.AreEqual(GetCell(actual.Worksheet, "E", 4).CellValue.InnerText, "Notes");
        }
示例#3
0
        public void InitializeFrom(string templatePath, IWorksheetWriter worksheetWriter)
        {
            if (worksheetWriter == null)
            {
                throw new ArgumentNullException("worksheetWriter");
            }
            byte[]       byteArray = File.ReadAllBytes(templatePath);
            MemoryStream stream    = new MemoryStream(byteArray);

            using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
            {
                // Change from template type to workbook type
                spreadsheetDoc.ChangeDocumentType(SpreadsheetDocumentType.Workbook);
                WorksheetPart worksheetPart = ExcelUtility.GetWorksheetPartByName(spreadsheetDoc, worksheetWriter.SheetName);
                if (worksheetPart != null)
                {
                    worksheetWriter.CreateHeader(worksheetPart);
                }
            }
            FileContentStream = stream;
        }
示例#4
0
 public void GivenNullDocument_WhenGetWorksheetPartByName_ThenThrowException()
 {
     TestExtensions.ExpectException <ArgumentNullException>(() => ExcelUtility.GetWorksheetPartByName(null, ""));
 }