locked
ExcelPackage RRS feed

  • Question

  • User1935984934 posted

    Can't get around this one, I know it is pretty obvious  but anyway can't find what's wrong.

    Imports System.IO
    Imports OfficeOpenXml
    
    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim FilePath As String = Server.MapPath("App_Data/Alumnos7.xls")
            Dim fsSource As FileStream = File.OpenRead(FilePath)
            Dim package As New ExcelPackage(fsSource)
            Dim dt As DataTable = ExcelPackageExtensions.ToDataTable(package)
    
    
        End Sub
    
    End Class

    Tuesday, May 29, 2018 3:24 PM

Answers

  • User753101303 posted

    Hi,

    Or the issue might be that this is an XLS file rather than an XLSX file ? Can you save back this file as an XLSX file and try again ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 29, 2018 3:56 PM

All replies

  • User475983607 posted

    Perhaps...

    Dim FilePath As String = Server.MapPath("~/App_Data/Alumnos7.xls")

    Try using the Visual Studio debugger.  Set a breakpoint and view the locals.  Have you verified the file exists?

    Tuesday, May 29, 2018 3:46 PM
  • User1935984934 posted

    Yes the file exists, I tried the code shown below, same error

    Dim FilePath As String = Server.MapPath("~/App_Data/Alumnos7.xls")
    If File.Exists(FilePath) Then
        Dim fsSource As FileStream = File.OpenRead(FilePath)
        Dim package As New ExcelPackage(fsSource)
        Dim dt As DataTable = ExcelPackageExtensions.ToDataTable(package)
    End If

    Tuesday, May 29, 2018 3:53 PM
  • User753101303 posted

    Hi,

    Or the issue might be that this is an XLS file rather than an XLSX file ? Can you save back this file as an XLSX file and try again ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 29, 2018 3:56 PM
  • User1935984934 posted

    Patrice,

    You were right, I grabbed a .XLSX file and try again and it went thru fine. I thought using EPplus would work for both old and new Excel file format but after Googling around I found out that it works only for .XLSX format.

    For the .XLS format I'll be using OLEDb

    Tuesday, May 29, 2018 4:06 PM