예제 #1
0
        public void CreateChangeSaveOpenReadWorks()
        {
            var           location  = new ExcelCellLocation("sheet1", 1, 3);
            var           value     = "asdas fsdl.ögkjd";
            var           readValue = string.Empty;
            IInMemoryFile excelFile = null;

            using (var context1 = new NpoiExcelContext())
            {
                context1.OpenExcel();

                context1.SetValue(location, value);

                excelFile = context1.WriteExcel("myExcel");
            }

            using (var context2 = new NpoiExcelContext())
            {
                context2.OpenExcel(excelFile);

                readValue = context2.GetValue(location);
            }

            readValue.Should().Be(value);
            excelFile.FileName.Should().Be("myExcel.xlsx");
        }
예제 #2
0
 /// <summary>
 ///     Writes the in memory file to a file on disk.
 /// </summary>
 /// <param name="inMemoryFile">The in memory file.</param>
 public static void WriteToFile(this IInMemoryFile inMemoryFile)
 {
     using (var file = File.Create(inMemoryFile.FileName))
     {
         var data = inMemoryFile.GetData();
         file.Write(data, 0, data.Length);
     }
 }
예제 #3
0
 public void OpenExcel(IInMemoryFile excelFile = null)
 {
     if (excelFile != null)
     {
         this.workbook = new XSSFWorkbook(excelFile.DataStream);
     }
     else
     {
         this.workbook = new XSSFWorkbook();
     }
 }
예제 #4
0
        /// <summary>
        ///     Converts a file into an system.net.mail attachment.
        /// </summary>
        /// <param name="inMemoryFile">The in memory file.</param>
        /// <returns>The attachement</returns>
        public static Attachment ToMailAttachment(this IInMemoryFile inMemoryFile)
        {
            var attachementInMemoryFile = inMemoryFile as AttachementInMemoryFile;

            if (attachementInMemoryFile != null)
            {
                return(attachementInMemoryFile.ToMailAttachment());
            }
            else
            {
                return(new Attachment(inMemoryFile.DataStream, inMemoryFile.FileName, inMemoryFile.ContentType));
            }
        }
예제 #5
0
 /// <summary>
 /// Gets the content of the file as base64 string.
 /// </summary>
 /// <param name="inMemoryFile">The in memory file.</param>
 /// <returns>The content as base64 string.</returns>
 public static string GetDataAsBase64(this IInMemoryFile inMemoryFile)
 {
     return(Convert.ToBase64String(inMemoryFile.GetData()));
 }