我下載了400多個Excel,是2003的xls格式的,使用NPOI讀取的時候報錯
Unexpected record type (HyperlinkRecord)
沒有找到解決此法的辦法,發現打開Excel,點擊一下保存,然后在使用NPOI讀取是沒問題的
問題是,400多個Excel,我不可能一個一個的去點擊保存,所以想了另外一個辦法,就是把這個xls格式的Excel都另存為xlsx格式即可,400多個xls改成xlsx格式的,手動改也是不現實的
所以要使用VBA,我參考的這篇文章,寫的很好
使用VBA批量轉換Excel格式,由.xls轉換成.xlsx
做法就是在xls文件夾內新建一個Excel,開啟宏,然后打開這個Excel,按下alt+F11,點擊sheet1輸入VB代碼
Sub xls2xlsx()
Dim FilePath, MyFile, iPath, Name, OutPath As String
iPath = ThisWorkbook.Path
OutPath = Dir(iPath & "\xlsx", vbDirectory)
If OutPath = "" Then
MkDir (iPath & "\xlsx")
End If
MyFile = Dir(iPath & "\*.xls")
If MyFile <> "" Then
Do
On Error Resume Next
If MyFile = ThisWorkbook.Name Then MyFile = Dir
Workbooks.Open (iPath & "\" & MyFile)
MyFile = Replace(MyFile, ".xls", ".xlsx")
Name = "\" & MyFile
FilePath = iPath & "\xlsx" & Name
Application.ScreenUpdating = False
ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Workbooks(MyFile).Close True
Application.ScreenUpdating = True
MyFile = Dir
Loop While MyFile <> ""
End If
End Sub
然后按下F5執行,靜候佳音即可