title: How to I create and return an Excel File with a controller in MVC 4 in vb.net?
body: <p>I am using ExcelLibrary <a href="https://code.google.com/p/excel-generator/downloads/list" rel="nofollow">enter link description here</a> because I don't want to install Microsoft Office Excel (microsoft.interop.office.excel)</p>
  
  <pre><code> Public Function ObtenerExcel() As ActionResult
        Dim workbook As New Workbook()
        Dim worksheet As New Worksheet("Sheet1")
        worksheet.Cells(5, 5) = New Cell(999999)
        worksheet.Cells(10, 10) = New Cell(12354)
        workbook.Worksheets.Add(worksheet)
  
        Dim stream As New System.IO.MemoryStream
        workbook.SaveToStream(stream)
        stream.Position = 0
  
        Dim buffer(4096) As Byte
        stream.Read(buffer, 0, buffer.Length)
  
        Return File(buffer, "application/vnd.ms-excel", "mytestfile.xls")
      End Function
  </code></pre>
  
  <p>This code return an excel file, but when I try to open this file, It shows an error message (Excel found unreadable content in 'text.xls'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.) and it doesn't shows anything.</p>
  
  <p>I working on Windows 8.1 (64 bits) and Microsoft Office 2013</p>