我把数据库某表导出txt后,出来的效果如下:123 李小明 233 a
1234 邓双双 43 b
12 郭若 556 c
22222 陈小三 44 d我想得到以下的效果,应该怎样让它自动补足空格?123 李小明 233 a
1234 邓双双 43 b
12 郭若 556 c
22222 陈小三 44 d 其中有个问题,名字那列当出现两个字的时候,它是前对齐,而第三列的数字却后面对齐,我应该怎么实现?
请高手门帮忙。
1234 邓双双 43 b
12 郭若 556 c
22222 陈小三 44 d我想得到以下的效果,应该怎样让它自动补足空格?123 李小明 233 a
1234 邓双双 43 b
12 郭若 556 c
22222 陈小三 44 d 其中有个问题,名字那列当出现两个字的时候,它是前对齐,而第三列的数字却后面对齐,我应该怎么实现?
请高手门帮忙。
解决方案 »
- WORD2007 组合对象如何设置排版格式为嵌入式
- VB中动态SQL问题
- 请问高手分数无限我有四千多分,都不知道怎么用了~
- 求助:用VB把数据导EXCEL中问题,(实时错误 '1004' 对象 'Range' 的方法 '_Global' 失败)
- 100分在这里:http://www.csdn.net/expert/topic/975/975146.xml?temp=.2975885,关于MCSD题库(for VB的)
- 使用DAO3.6,如何在一个Access数据库中建立一个表的副本。难道非要用先建表再逐个拷贝字段的方式吗?
- 請問imagelist
- access的压缩问题
- 如何打印一个窗体中所有控件的某些属性值?
- !!help!!怎样在程序中添加快速显示窗体?
- 高分跪求贵人相助!!!急!!!只有五个月的时间,学什么语言可以快速找份工作?
- 说说自己。。。
再简单一点就是用format :
左对齐:format(s,"!@@@@@@")
右对齐:format(s,"@@@@@@")
其中:s是你要对齐的文本,@是点位符(空格),可以根据s长度来定义多少个@,自己写个函数就能实现你的要求....
如果是自己输出文本,用 Format 控制对齐(4楼)。
WritStr = ""
For i = 0 To rs.Fields.Count - 1
WritStr = WritStr & "" & Trim(ISNULL2SPACE(rs(i))) & ","
Next
Print #Fid, WritStr
rs.MoveNext
lngCount = lngCount + 1
Wend
Private Sub Command1_Click()
'x1.txt内容如下:
'123 李小明 233 a
'1234 邓双双 43 b
'12 郭若 556 c
'22222 陈小三 44 d
'第二列名字的第一个字对齐,第三列数字最后一位对齐,第四列是第一位对齐
'生成文件x2.txtDim tmp, tmp1(3), tmp2(3)
Open "c:\x1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
While InStr(tmp, " ") > 0
tmp = Replace(tmp, " ", " ")
Wend
tmp1(0) = Split(tmp)(0)
tmp1(1) = Split(tmp)(1)
tmp1(2) = Split(tmp)(2)
tmp1(3) = Split(tmp)(3)
If tmp2(0) < Len(tmp1(0)) Then tmp2(0) = Len(tmp1(0))
If tmp2(1) < Len(tmp1(1)) Then tmp2(1) = Len(tmp1(1))
If tmp2(2) < Len(tmp1(2)) Then tmp2(2) = Len(tmp1(2))
If tmp2(3) < Len(tmp1(3)) Then tmp2(3) = Len(tmp1(3))
Loop
Close #1
Open "c:\x1.txt" For Input As #1
Open "c:\x2.txt" For Output As #2Do While Not EOF(1)
Line Input #1, tmp
While InStr(tmp, " ") > 0
tmp = Replace(tmp, " ", " ")
Wend
tmp1(0) = Split(tmp)(0)
tmp1(1) = Split(tmp)(1)
tmp1(2) = Split(tmp)(2)
tmp1(3) = Split(tmp)(3)
tmp = ""
tmp1(0) = tmp1(0) & Space(tmp2(0) - Len(tmp1(0)))
tmp = tmp & tmp1(0) & " "
For i = 1 To 3
If IsNumeric(tmp1(i)) Then
tmp1(i) = Space(tmp2(i) - Len(tmp1(i))) & tmp1(i)
Else
tmp1(i) = tmp1(i) & Space((tmp2(i) - Len(tmp1(i))) * 2)
End If
tmp = tmp & tmp1(i) & " "
Next
tmp = RTrim(tmp)
Print #2, tmp
Loop
Close #1, #2
End Sub
C:\x1.txt改成你的原文件路径
c:\x2.txt改成你要的文件路径试试
While Not rs.EOF
WritStr(0) = format(rs(0) & "","!@@@@@@") '左对齐
WritStr(1) = format(rs(1) & "","!@@@@@@@@@") '左对齐
WritStr(2) = format(rs(2) & "","@@@@@@@") '右对齐
WritStr(3) = format(rs(3) & "","@@@@@@") '右对齐
Print #Fid, join(WritStr)
rs.MoveNext
lngCount = lngCount + 1
Wend
'x1.txt内容如下:
'123 李小明 233 a
'1234 邓双双 43 b
'12 郭若 556 c
'22222 陈小三 44 d
'第二列名字的第一个字对齐,第三列数字最后一位对齐,第四列是第一位对齐Dim tmp, tmp1(3), tmp2(3)
Open "c:\x1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
While InStr(tmp, " ") > 0
tmp = Replace(tmp, " ", " ")
Wend
For i = 0 To 3
tmp1(i) = Split(tmp)(i)
Next
For i = 0 To 3
If tmp2(i) < Len(tmp1(i)) Then tmp2(i) = Len(tmp1(i))
Next
Loop
Close #1
Open "c:\x1.txt" For Input As #1
Open "c:\x2.txt" For Output As #2Do While Not EOF(1)
Line Input #1, tmp
While InStr(tmp, " ") > 0
tmp = Replace(tmp, " ", " ")
Wend
For i = 0 To 3
tmp1(i) = Split(tmp)(i)
Next
tmp = ""
tmp1(0) = tmp1(0) & Space(tmp2(0) - Len(tmp1(0)))
tmp = tmp & tmp1(0) & " "
For i = 1 To 3
If IsNumeric(tmp1(i)) Then
tmp1(i) = Space(tmp2(i) - Len(tmp1(i))) & tmp1(i)
Else
tmp1(i) = tmp1(i) & Space((tmp2(i) - Len(tmp1(i))) * 2)
End If
tmp = tmp & tmp1(i) & " "
Next
tmp = RTrim(tmp)
Print #2, tmp
Loop
Close #1, #2
End Sub
WritStr = WritStr & Left$(rs("Name") & string(4," "),4)
或者在 SQL 语句中用中文空格补齐,更方便一点。