我想要做的是轉換器。由於它被指定爲[Sheet1 $],因此我在打開Excel文件時遇到了問題。如果工作表已重命名,我的代碼不會讀取它。有沒有辦法讓我得到任何名單的平板電腦?如何閱讀excel文件的表格,而不管它是否被重命名?
Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
If cmbPortal.Text.Length = 0 Then
MessageBox.Show("Select portal to process first", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Select Case cmbPortal.Text
Case "Robinsons"
FileFilter = "Portable Document File (*.pdf)|*.pdf"
txtFilePath.Text = parse.showdialog(FileFilter)
If txtFilePath.Text = Nothing Then
MessageBox.Show("No file was selected", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Case "Waltermart"
FileFilter = "Portable Document File (*.pdf)|*.pdf"
txtFilePath.Text = parse.showdialog(FileFilter)
If txtFilePath.Text = Nothing Then
MessageBox.Show("No file was selected", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Case "7-11"
Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
.FileName = "Excel File"
.Title = "Open File"
.InitialDirectory = "C:\User\Desktop"
.Filter = "EXCEL|*.xls;*.xlsx;*.xlsm;*.xlsb"
.FilterIndex = 1
End With
If OpenFileDialog1.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
Me.Cursor = Cursors.WaitCursor
Try
Dim FileName As String = OpenFileDialog1.FileName
Dim strConnString As String
strConnString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & FileName & ";"
Dim strSQL As String
strSQL = "SELECT * FROM [Sheet1$]"
Dim y As New Odbc.OdbcDataAdapter(strSQL, strConnString)
y.Fill(RetVal)
txtFilePath.Text = FileName
Catch
MessageBox.Show("An Error Occurred, Please Contact MIS for Assistance", "SYSTEM", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Me.Cursor = Cursors.Default
ElseIf txtFilePath.Text = Nothing Then
MessageBox.Show("No file was selected", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Me.Cursor = Cursors.Default
End Select
If txtFilePath.Text.Length = 0 Then
btnSelect.Enabled = True
btnConvert.Enabled = False
cmbPortal.Enabled = True
Else
btnSelect.Enabled = False
btnConvert.Enabled = True
cmbPortal.Enabled = False
End If
End If
End Sub
您正在檢索的工作表的索引是否已修復?例如。它總是第一張工作表嗎? –
根據你的問題的內容,你的標題也是誤導性的。 –
它始終是第一張工作表,並且基於代碼,只有在第一張工作表被命名爲Sheet1時纔會指定它。我想要做的是仍然閱讀第一張紙,不管它是否被重命名。我對標題感到非常抱歉,感謝您的注意。 – Biboy