私はExcelファイルからデータを読み込むプログラムを作成しようとしています。試してから数時間後、ついにそれが働いています。しかし、特に大量の行と列については、非常に遅く動作することに気付きました。私の他のPCでそれを試してみてください。おそらくそれはPCの問題かもしれませんが、残念ながら他の人も同様に遅いです。VB.Net - Excelファイルからのデータ読み込みが遅い
変更や削除や追加が必要なことはありますか?
Public Sub LoopExcel()
Dim colfrom As Integer = Asc(txtColFrom.Text)
Dim colto As Integer = Asc(txtColTo.Text)
Dim rowfrom As Integer = Integer.Parse(txtRowFrom.Text)
Dim rowto As Integer = Integer.Parse(txtRowTo.Text)
For rowindex = rowfrom To rowto
For colindex = colfrom To colto
Dim str As String = OpenExcelGetData(txtFileName.Text, rowindex, Convert.ToChar(colindex)).ToString
Console.WriteLine(str)
Next
Next
End Sub
Public Function OpenExcelGetData(ByVal fileNameAndPath As String, ByVal rowIndex As Integer, ByVal columnIndex As String) As Object
Dim oExcelApp As New Excel.ApplicationClass
Dim oExcelBook As Excel.Workbook
Dim oExcelSheet As Excel.Worksheet
Dim sheetNumber As Integer = 1 '1-based array
Dim oData As Object = Nothing
Try
oExcelBook = oExcelApp.Workbooks.Open(fileNameAndPath)
oExcelSheet = CType(oExcelBook.Worksheets(sheetNumber), Excel.Worksheet)
'Read data
Dim excelRange As String = columnIndex & rowIndex.ToString()
oData = oExcelSheet.Range(excelRange).Value
Catch exp As COMException
MessageBox.Show(exp.Message)
Catch exp As Exception
MessageBox.Show(exp.Message)
End Try
Return oData
End Function
おそらく、コードレビューの専用サイトである[ここ](https://codereview.stackexchange.com/)の質問を投稿してください。 – Mrig
[こちら](https://stackoverflow.com/a/16051/468973)は、自動化を使用する代わりです。 – Magnus