当我从Excel工作表中写入内容时,如何避免文本文件中的换行器?

时间:2015-05-27 06:59:50

标签: excel vba excel-vba

用于将excel表格中的内容写入文本文件的我的VBA代码如下所示。

ActiveWorkbook.Sheets("Sheet1").Activate
With ActiveSheet
    .Range(.Cells(1, 1), .Cells.SpecialCells(xlCellTypeLastCell)).Select
End With
Dim strPath As String
Dim FSO As Object
Dim oFile As Object
Set oFile = Nothing
Dim c As Range
Dim linefeed_remover
strPath = "path"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.CreateTextFile(strPath & filesname)
For Each c In Selection
    oFile.Write Application.WorksheetFunction.Clean(c.Value) & vbLf
Next c
oFile.Close
strNameOld = strName & "_Old"
'MsgBox "File Created"
'conn2.Close

任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

<强>建议

  1. 不要在一个范围内循环细胞。将它们存储在一个数组中并循环遍历该数组。这是一种更快的方法。

  2. 使用数组还可以让我们知道我们正在处理哪条记录。如果我们使用最后一条记录,我们可以跳过添加生命饲料。

  3. 见这个例子。

    $sql = "SELECT image FROM table WHERE id=1";
    $result = mysql_query("$sql");
    header("Content-type: image/jpeg");
    echo mysql_result($result, 0);
    
相关问题