简体   繁体   English

尝试导出Excel C#时出现磁盘错误

[英]Disk error while trying to export excel c#

I am trying to export an excel file using EPPlus 我正在尝试使用EPPlus导出Excel文件

   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 (来自HRESULT的异常:0x8003001D(STG_E_WRITEFAULT))“-写入操作期间发生磁盘错误

不确定,但尝试使用空白密码读取excel文件:

 new ExcelPackage(FileUpload1.PostedFile.InputStream, ""))

This could relate to several problems. 这可能与几个问题有关。 A couple of different solutions have been suggested here: 这里提出了几种不同的解决方案:

A disk error occurred during a write operation. 写操作期间发生磁盘错误。 (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT)) (来自HRESULT的异常:0x8003001D(STG_E_WRITEFAULT))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM