This project has moved. For the latest updates, please go here.

FormatException

Aug 2, 2012 at 11:08 AM
Edited Aug 2, 2012 at 11:47 AM

Hi!

this code :

SPFile spfile = web.GetFile("http://localhost/Deps/SUP/Shared Documents/testnew.xlsx");
                       if (spfile.Exists)
                       {
                           byte[] byteArray = spfile.OpenBinary();
                           MemoryStream _stream = new MemoryStream();
                           _stream.Position = _stream.Length;
                           _stream.Write(byteArray, 0, byteArray.Length);
                           var workbook = new XLWorkbook(_stream);
                            // do something
                          _stream.Flush();
                              workbook.SaveAs(_stream);
                               spfile.SaveBinary(_stream);
                               spfile.Update();
                           
                       }
                       else
                       {
                           //problem!!! how create file ? 
                          // my attempt
                        byte[] test = System.Text.Encoding.UTF8.GetBytes("hello, world");
                           MemoryStream _stream = new MemoryStream();
                         _stream.Write(test, 0, test.Length);   
                         var workbook = new XLWorkbook(_stream); // this line failed
               }

error : file contains corrupted data

please, help. how create file &

Coordinator
Aug 2, 2012 at 2:33 PM
"hello, world" is not a valid Excel file.
Aug 3, 2012 at 6:38 AM

ok. how possible method  create file ?

Aug 3, 2012 at 7:14 AM

solved very simple

delete argument in line

var workbook = new XLWorkbook();