将Excel数据写入Txt文件的问题 [英] Problem with writing Excel data to Txt file

查看:83
本文介绍了将Excel数据写入Txt文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在宏中,我打开了一个新的文本文件,并将数据从excel工作表复制到该文本文件.它工作正常,并且我也在文本文件中获取数据.但是........
格式不整齐,例如

名字姓氏
鲍勃·约翰
Qwak水晶


但我要这样

名字姓氏
鲍勃·约翰
Qwak水晶

即使我尝试在单词之间插入空格(例如5个空格),一行与另一行的格式也不同,请给这个建议......

In a macro I have opened a new text file and copying data from excel sheet to that text file.It is working fine and i am getting data in the text file also.But........
The format is not in Good order,like

FirstName LastName
Bob John
Qwak crystal


But i want in this manner

FirstName LastName
Bob John
Qwak crystal

Even if i try to insert spaces also (Eg 5 spaces)between words,The format of one row to other row is different,Plz Give suggestions for this...........

推荐答案

在将数据添加到文本文件之前,请在宏中尝试使用此功能.


Try this function in your macro, before adding your data to text file.


''sValue=text of your cell
''sPad_Text=padding character - " " in most cases
''sType="Left"|"Right"
''iMaxSize=desired width of field (greater than maximum size)
Public Function pad(svalue, spad_text, stype, imaxsize)
Dim length
length = Len(svalue)
If stype = "Left" Then
pad = String(imaxsize - length, spad_text) & svalue
Else
pad = svalue & String(imaxsize - length, spad_text)
End If
End Function


代替空格,将制表符放在两列之间
Instead on Spaces put Tabs between the two columns


这篇关于将Excel数据写入Txt文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆