我有,我想Visual Studio 2015 - 操纵Excel?
- 清洁通过删除有星号的航向数据的列750个Excel文件,
- 然后采取一些数据,并把它放在一个新的工作簿的工作表,其他数据放入同一个工作簿工作表中,并将一些其他数据放入第二个新工作簿中。
我在Visual Studio 2015年创建的WPF项目与2个单选按钮一个小对话框
- 干净的数据,
- 产生新的文件。
这是我的VB代码:
Class MainWindow
Dim wb As Microsoft.Office.Interop.Excel._Workbook
Dim ws As Microsoft.Office.Interop.Excel._Worksheet
Dim iCol As Integer
Dim strName As String
Dim iIndex As Integer
Dim strPath As String
Dim strFile As String
Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
If cleanRadioButton.IsChecked = True Then
strPath = "c:\test\old\"
strFile = Dir(strPath & "*.csv")
Do While strFile <> ""
wb = wb.Open(Filename:=strPath & strFile)
'Loop through the sheets.
For iIndex = 1 To Application.Worksheets.Count
ws = Application.Worksheets(iIndex)
'Loop through the columns.
For iCol = 1 To ws.UsedRange.Columns.Count
'Check row 1 of this column for the char of *
If InStr(ws.Cells(10, iCol).Value, "*") > 0 Then
'We have found a column with the char of *
ws.Columns(iCol).EntireColumn.Delete
ws.Columns(iCol + 1).EntireColumn.Delete
ws.Columns(iCol + 2).EntireColumn.Delete
End If
Next iCol
Next iIndex
wb.SaveAs(Filename:="C:\test\new\" & wb.Name, FileFormat:=xlOpenXMLWorkbook)
wb.Close(SaveChanges:=False)
strFile = Dir()
Loop
MessageBox.Show("The csv files have now been cleaned. Congrats.")
Else inputRadioButton.IsChecked = True
MessageBox.Show("The data has now been split into Trajectory and ForcePlate input files. High 5.")
End If
End Sub
End Class
我得到的3个错误,但无法工作,如何解决这些问题。
一个)工作表是不应用[线19]
b)中的一员工作表是不应用的成员[线路20]
C) 'xlOpenXMLWorkbook' 未声明。由于其保护级别,它可能无法访问。
我使用VB.Net和VBA。 VB.Net具有丰富的功能,其中包括访问以任何版本的Excel保存的工作簿,并且生成的可执行文件**可以比VBA宏快上百倍。我认为VB.Net是更好的语言,我比VBA更多地使用它。但是,从VB.Net访问工作簿的速度很慢。如果程序的唯一目标是操作工作簿,那么我会使用VBA。 –