问题是这样的:
有张excel表,内容如下:
Id Name Price compId
1 a 1 c001
2 b 2 c002
3 c 3 c001
4 d 4 c002我想在VB里实现以下功能:
将上面的excel表按照compId 分类,分别导出到word中。如,上面的excel生成了两个word文件,分别是word1.doc:
Id Name Price compId
1 a 1 c001
3 c 3 c001word2.doc:
Id Name Price compId
2 a 2 c002
4 c 4 c002
该功能在vb中如何实现呢?望高人指点!!!
有张excel表,内容如下:
Id Name Price compId
1 a 1 c001
2 b 2 c002
3 c 3 c001
4 d 4 c002我想在VB里实现以下功能:
将上面的excel表按照compId 分类,分别导出到word中。如,上面的excel生成了两个word文件,分别是word1.doc:
Id Name Price compId
1 a 1 c001
3 c 3 c001word2.doc:
Id Name Price compId
2 a 2 c002
4 c 4 c002
该功能在vb中如何实现呢?望高人指点!!!
Dim a() As String
Dim b() As String
Dim i As Integer
Dim ll As Integer
Private Sub Command1_Click() '打开文件,在text1 中显示
Text1.Text = ""
C1.FileName = ""
C1.CancelError = False
C1.InitDir = App.Path
C1.Filter = "(*.xls)|*.xls|(All*.*)|*.*"
C1.Action = 1
Open C1.FileName For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
i = i + 1
ReDim Preserve a(i)
Input #1, a(i) ' 读入一行数据并将其赋予某变量。
Text1.Text = Text1.Text + a(i) + Chr(13) + Chr(10) '不显示,去掉此行
Loop
Close #1 ' 关闭文件。End SubPrivate Sub Command2_Click() '在text2中输入c001 或c002作为查询分别保存就可以了
On Error Resume Next
Dim j As Integer
Dim g As String
Dim jj As Integer
For j = 1 To i
g = Right(a(j), 4)
If g = Text2.Text Then ReDim Preserve b(i): ll = ll + 1: b(ll) = a(j)
Next j
C1.FileName = ""
C1.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt
C1.InitDir = App.Path
C1.Filter = "(*.doc)|*.doc|(All*.*)|*.*"
C1.Action = 2
Open C1.FileName For Output As #10
Print #10, a(1)
For jj = 1 To ll
Print #10, b(jj)
Next jj
Close #10End Sub其中c1为工程引用microsot common dialog control 6.0 将commondialog1 改名为c1