紧急求助:excel转word
问题是这样的:有张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 c001
word2.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 Sub
Private 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 #10
End Sub
其中c1为工程引用microsot common dialog control 6.0 将commondialog1 改名为c1
--------------------编程问答-------------------- 这个不懂 --------------------编程问答-------------------- 在EXCEL中排个序,复制粘贴不就行了。 --------------------编程问答-------------------- 在word也要是表格形式显示吗?? --------------------编程问答-------------------- 打开Excel文档,先排个序,再相应的数据取出来,分别放到两个word里
补充:VB , 基础类