Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with my project ,

i want to read xls file using eppplus ,

but it show an error like this

"
Quote:
An exception of type 'System.Exception' occurred in EPPlus.dll but was not handled in user code

Additional information: Can not open the package. Package is an OLE compound document. If this is an encrypted package, please supply the password


how can i solve this?
i read some article, say that eppplus does not support for xls file ,
so i think i should change xls file into xlsx ,
how can i did it?

What I have tried:

this is my code ,
protected void check(object sender, EventArgs e)
      {
          if (FileUpload1.HasFile)
          {
              string filename = "Hr_Report_" + DateTime.Now.ToString("dddd_dd_MMMM_yyyy") + ".xlsx";
              FileUpload1.SaveAs(temp_file + filename);
              string tempfile = temp_file + filename;
              string c = @tempfile;
              DataTable table = new DataTable();

              FileInfo existingFile = new FileInfo(tempfile); //+ FileUpload1.FileName);
              using (ExcelPackage package = new ExcelPackage(existingFile))
              {
                  ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
                  int colCount = worksheet.Dimension.End.Column;
                  int rowCount = worksheet.Dimension.End.Row;
                  table.Columns.Add("Emp_NIK", typeof(string));
                  table.Columns.Add("Timer_Finger", typeof(DateTime));
                  table.Columns.Add("Status", typeof(string));
                  for (int i = 1; i < rowCount; i++)
                  {
                      TableRow row = new TableRow();
                      TableCell cell1 = new TableCell();
                      cell1.Text = worksheet.Cells[i + 1, 2].Text.ToString();//+worksheet.Cells[i + 1, 3].Value.ToString() + " " + worksheet.Cells[i + 1, 2].Value.ToString() + " Baris ke " + i;
                      row.Cells.Add(cell1);
                      myTable.Rows.Add(row);

                  }
              }
          }
          else
          {
              Response.Write("<script>window.alert('File Belum diupload')</script>");
          }
      }
Posted
Updated 11-May-20 21:00pm
Comments
markelee-advid 19-May-20 4:10am    
As Maciej mentioned, the EPPlus doesn't support XLS format, only XLSX.
Nevertheless, you could try using GemBox.Spreadsheet which supports various formats like XLS, XLSX, ODS, etc. using the same API (ExcelFile.Load). For instance, take a look at this C# example of reading Excel files.

1 solution

Yes, EPPlus does NOT support old format of Excel file. You need to use another open source option. See: Reading Excel Files In .NET Core - .NET Core Tutorials[^]
 
Share this answer
 
Comments
CPallini 12-May-20 3:22am    
5.
Maciej Los 12-May-20 3:23am    
Thank you, Carlo.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900