We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting corrupted files- don't know why; ASP MVC- C#- DataTable

Files are downloaded, they have a size


public ActionResult ExcelDownload(string id)
{
var wb = new Aspose.Cells.Workbook();
wb.Worksheets.Add();
var ws = wb.Worksheets[0];
ws.Cells[0, 0].Value = “Maintained Table Name”;
ws.Cells[1, 0].Value = “Last Updated On”;
ws.Cells[0, 1].Value = id;
ws.Cells[1, 1].Value = RowService.Lastupdated(id); //DateTime?
System.Data.DataTable dt = RowService.Export(id);
ws.Cells.ImportDataTable(dt, true, 2, 0);
wb.FileFormat = Aspose.Cells.FileFormatType.Xlsx;
var s = wb.SaveToStream();
s.Position = 0;
string fileName = id+".xlsx";
return File(s, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}

file has contents too, but not very xml like:
) [ ý
) ý
) ý
) ý
) ý
) ý
)a ý
) ý
) ] ý
)
^ ý
* _ ý
* \ ý
* ý

Hi BHamer,

Thanks for your posting and using Aspose.Cells.

Workbook.SaveToStream() saves your workbook in XLS format. If you want to save your workbook in XLSX format, then do the following code change.

Please change these lines

var s = wb.SaveToStream();
s.Position = 0;

into the following lines

MemoryStream s = new MemoryStream();
workbook.Save(s, SaveFormat.Xlsx);
s.Position = 0;

It should fix your issue. Please also download and try the latest version: Aspose.Cells
for .NET v8.0.1.4
and see if it makes any difference.

If your issue still occurs, then please provide us your runnable sample project. We will look into it and help you asap.


ok, that did the trick, files are no longer corrupted and download fine.


getting the extra sheet with the evaluation warning tough, and this is with a successfully loading license file (well I assume so, not exceptions)

public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();

WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);

//Instantiate the License class
Aspose.Cells.GridWeb.License license = new Aspose.Cells.GridWeb.License();

//Pass only the name of the license file embedded in the assembly
license.SetLicense(“Aspose.Cells.lic”);

}
}

Hi there,


Good to know that you have moved past the previously reported problem. Regarding the evaluation worksheets in the resultant spreadsheet, this is because you are not setting the license for Aspose.Cells API, yet you are using it in your application. Please note, you have to set the license for both components separately, that is; for Aspose.Cells.GridWeb for .NET and Aspose.Cells for .NET.

Your licensing code should look like as follow,

C#

//Instantiate the License class for GridWeb
Aspose.Cells.GridWeb.License licenseGridWeb = new Aspose.Cells.GridWeb.License();
//Pass only the name of the license file embedded in the assembly
licenseGridWeb.SetLicense(“Aspose.Cells.lic”);

//Instantiate the License class for Cells
Aspose.Cells.License licenseCells = new Aspose.Cells.License();
//Pass only the name of the license file embedded in the assembly
licenseCells.SetLicense(“Aspose.Cells.lic”);