0

I want to import excel to devexpress grid.

When I runing in my PC, It work well.

But "Invalid file signature" error occurs in customer's PC.

So I get the customer's excel file(.xlsx) and open it my PC.

No error occurs in my PC. ...Why?

Here, my code to open excel file.

Dim stream As FileStream = File.Open(filePath, FileMode.Open, FileAccess.Read)

If UCase(strExt) = "XLS" Then

    Dim excelReader As IExcelDataReader = ExcelReaderFactory.CreateBinaryReader(stream)
    Dim excelDsConf As ExcelDataSetConfiguration = New ExcelDataSetConfiguration()
    excelDsConf.ConfigureDataTable = Function() New ExcelDataTableConfiguration() With {
    .UseHeaderRow = True
    }
    DtSet = excelReader.AsDataSet(excelDsConf)
    DtSet.Tables(0).TableName = "ExcelData"
Else 'XLSX
    Dim excelReader As IExcelDataReader = ExcelReaderFactory.CreateOpenXmlReader(stream)

    Dim excelDsConf As ExcelDataSetConfiguration = New ExcelDataSetConfiguration()
    excelDsConf.ConfigureDataTable = Function() New ExcelDataTableConfiguration() With {
    .UseHeaderRow = True
    }
    DtSet = excelReader.AsDataSet(excelDsConf)
    DtSet.Tables(0).TableName = "ExcelData"
End If

.Netframework is 4.0

Why "Invalid file signature" error occur in customer's PC?

What should I check on the customer's PC?

js u
  • 71
  • 6
  • https://github.com/ExcelDataReader/ExcelDataReader/issues/83 suggests changing CreateBinaryReader to CreateReader. Also look at https://stackoverflow.com/questions/51079664/c-sharp-error-with-exceldatareader – Andrew Mortimer Dec 10 '21 at 06:03
  • @AndrewMortimer I change that. But it occur same error... – js u Dec 16 '21 at 06:01

0 Answers0