I am trying to export an excel file using EPPlus
if (FileUpload1.HasFile && Path.GetExtension(FileUpload1.FileName) == ".xlsx")
{
bo.ExcelFile = txtFileName.Text;
bo.ExcelFileBranch = txtBranchName.Text;
bo.ExcelFileFromDate = txtValidFrom.Text;
bo.ExcelFileToDate = txtValidTo.Text;
using (var excel = new ExcelPackage(FileUpload1.PostedFile.InputStream))
{
var tbl = new DataTable();
var ws = excel.Workbook.Worksheets.First();
var hasHeader = false; // adjust accordingly
// add DataColumns to DataTable
foreach (var firstRowCell in ws.Cells[1, 1, 1, ws.Dimension.End.Column])
tbl.Columns.Add(hasHeader ? String.Format("Column {0}", firstRowCell.Start.Column)
: firstRowCell.Text);
// add DataRows to DataTable
int startRow = hasHeader ? 1 : 2;
for (int rowNum = startRow; rowNum <= ws.Dimension.End.Row; rowNum++)
{
var wsRow = ws.Cells[rowNum, 1, rowNum, ws.Dimension.End.Column];
DataRow row = tbl.NewRow();
foreach (var cell in wsRow)
row[cell.Start.Column - 1] = cell.Text;
tbl.Rows.Add(row);
}
But i am getting the following error :
(Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))"- Disk error occured during write operation
Not sure but try to read the excel file using a blank password :
new ExcelPackage(FileUpload1.PostedFile.InputStream, ""))
This could relate to several problems. A couple of different solutions have been suggested here:
User contributions licensed under CC BY-SA 3.0