VB怎么把excel内容导出成这样的txt文件内容 5
我想把excel里的内容显示成这样的txt内容,而且符号什么都要有~!PrivateSubCommand1_Click()DimxlsAppAsExcel.Applica...
我想把excel里的内容显示成这样的txt内容,而且符号什么都要有~!
Private Sub Command1_Click()
Dim xlsApp As Excel.Application '声明对象变量
Dim H As Long
Dim AStr As String
Set xlsApp = Excel.Application '实例化对象
xlsApp.Visible = False '使Excel隐藏不可见
xlsApp.Workbooks.Open ("e:\源文件.xls")
AStr = ""
H = 1 '假设数据从第一行开始,如果第一行是列名称,就改为从2开始
Do While xlsApp.Application.ActiveWorkbook.Sheets("Sheet1").Range("A" & CStr(H)).Value <> ""
AStr = AStr & xlsApp.Application.ActiveWorkbook.Sheets("Sheet1").Range("A" & CStr(H)).Value & _
Range("b" & CStr(H)) & Range("c" & CStr(H)) & Range("d" & CStr(H)) & Range("e" & CStr(H)) & _
Range("f" & CStr(H)) & vbCrLf
H = H + 1
Loop
Text1.Text = AStr
xlsApp.ActiveWorkbook.Close savechanges:=True '关闭活动工作簿同时保存对它的更改。
xlsApp.Quit '关闭EXCELL
Set xlsApp = Nothing
End Sub 展开
Private Sub Command1_Click()
Dim xlsApp As Excel.Application '声明对象变量
Dim H As Long
Dim AStr As String
Set xlsApp = Excel.Application '实例化对象
xlsApp.Visible = False '使Excel隐藏不可见
xlsApp.Workbooks.Open ("e:\源文件.xls")
AStr = ""
H = 1 '假设数据从第一行开始,如果第一行是列名称,就改为从2开始
Do While xlsApp.Application.ActiveWorkbook.Sheets("Sheet1").Range("A" & CStr(H)).Value <> ""
AStr = AStr & xlsApp.Application.ActiveWorkbook.Sheets("Sheet1").Range("A" & CStr(H)).Value & _
Range("b" & CStr(H)) & Range("c" & CStr(H)) & Range("d" & CStr(H)) & Range("e" & CStr(H)) & _
Range("f" & CStr(H)) & vbCrLf
H = H + 1
Loop
Text1.Text = AStr
xlsApp.ActiveWorkbook.Close savechanges:=True '关闭活动工作簿同时保存对它的更改。
xlsApp.Quit '关闭EXCELL
Set xlsApp = Nothing
End Sub 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |