回复 3楼randomcic的帖子
不太清楚你的excel文件具体是什么格式。仅从你的描述来看,你的两个excel文件格式是不一致的。一个是.xls文件,另一个是.xlsx文件。
如果你自己不能判断,那么使用GetExcelSheetList方法之前,可以添加判断IsExcelFile方法,如果是True,就可以使用GetExcelSheetList方法。否则使用IsExcel2007File方法判断是不是.xlsx后缀名的文件,然后使用 OpenExcel2007File方法。
有关 OpenExcel2007File方法的文档请参考:
http://helpcentral.componentone. ... nct278.html#1410199
我也已经在VisualStudio VB和VB6.0下测试过,没有重现你提到的方法不存在的问题。
特别注意的是:在VisualStudio VB下使用GetExcelSheetList方法,获取到的List(0)为null。
这个问题我已经提交到产品组进行确认。
目前来说,给你提供的解决方法,只有先通过导入读取excel文件,然后通过fpspread.SheetName获取文件名。
代码参考:
- Dim y As Boolean, z As Boolean
- Dim Var As Object
- Dim x As Integer, listcount As Integer, handle As Integer
- Dim List(10) As String
- If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
- ' Check if file is an Excel file and set result to x
- x = fpSpread1.IsExcelFile(OpenFileDialog1.FileName)
- ' If file is Excel file, tell user, import sheet
- ' list, and set result to y
- If x = 1 Then
- MsgBox("File is an Excel file.", , "File Type")
- y = fpSpread1.GetExcelSheetList(OpenFileDialog1.FileName, List, listcount, "C:\ILOGFILE.TXT", handle, True)
- ReDim List(listcount)
- ' If received sheet list, tell user, import file,
- ' and set result to z
- If y = True Then
- MsgBox("Got sheet list.", , "Status")
- z = fpSpread1.ImportExcelSheet(handle, 0)
- MsgBox(fpSpread1.SheetName, , "Result")
- ' Tell user result based on T/F value of z
- If z = True Then
- MsgBox("Import complete.", , "Result")
- Else
- MsgBox("Import did not succeed.", , "Result")
- End If
- Else
- ' Tell user cannot obtain sheet list
- MsgBox("Cannot return information for Excel file.", , "Result")
- End If
- Else
- ' Tell user file is not Excel file or is locked
- MsgBox("File is not an Excel file or is locked and cannot be imported.", , "Invalid File Type or Locked")
- End If
- End If
复制代码 |