使用“打印”时的空格在VBA中
由于某种原因,我在尝试打印到平面文本文件时,每个值前面都有很多空格。
'append headers
Cells(start_row - 2, 1).Select
For i = 1 To ActiveCell.SpecialCells(xlLastCell).Column
If ActiveCell.Offset(0, 1).Column = ActiveCell.SpecialCells(xlLastCell).Column Then
Print #finalCSV, Cells(start_row - 2, i) & "\n",
Else
Print #finalCSV, Cells(start_row - 2, i) & ",",
End If
Next i
输出示例:
DC Capacity:hi, Resistive Capacity:lo, Resistive Capacity:hi, Reactive Capacity:lo,
有什么方法可以去掉这些空格吗?
For some reason I am getting a lot of spaces in front of each value while trying to print to a flat text file.
'append headers
Cells(start_row - 2, 1).Select
For i = 1 To ActiveCell.SpecialCells(xlLastCell).Column
If ActiveCell.Offset(0, 1).Column = ActiveCell.SpecialCells(xlLastCell).Column Then
Print #finalCSV, Cells(start_row - 2, i) & "\n",
Else
Print #finalCSV, Cells(start_row - 2, i) & ",",
End If
Next i
Example output:
DC Capacity:hi, Resistive Capacity:lo, Resistive Capacity:hi, Reactive Capacity:lo,
Is there any way to get rid of these spaces?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我没记错的话,VB 中的逗号会插入制表符,而分号只会抑制换行符。
If I remember my VB correctly, a comma inserts a tab, while a semicolon just suppresses the newline.
文森特的答案是正确的,但我想让它更清楚:
将给出这种输出:
并在句子末尾使用分号:
会给你这个输出:
Vincent's answer is right but I want to make it even more clear:
will give this kind of output:
and using semicolon at the end of the sentence:
will give you this output: