【问题标题】:Output from Excel to text file using VBA, "UTF-8 Unix" format needed使用 VBA 从 Excel 输出到文本文件,需要“UTF-8 Unix”格式
【发布时间】:2016-12-13 11:37:51
【问题描述】:

我在 Excel 文件中有一些数据,我需要与他人分享。 对方对格式有特定要求:文本文件、*.dat 名称、管道分隔等。

所以我创建了一个 VBA 代码,以使用此站点中的示例将数据提取到文本文件中。

目前我的文件未被接受,因为:“它不是 UTF-8 UNIX 格式”。 我从互联网上尝试了多种解决方案,但每次我收到的答案都是“UTF-8 PC 格式”或“Unicode 格式”。

有人可以帮我解决这个问题吗?到目前为止,这是我所拥有的:

'create output (this is from my initial version)
Set Fileout = fso.CreateTextFile(myFile, True, True)
For y = 2 To a
Fileout.WriteLine .Cells(y, 59)
Next y
Fileout.Close

'this is from my second conversion attempt, where I received UTF-8 PC format
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Position = 0
stream.Charset = "UTF-8"
stream.LoadFromFile myFile

'This is my latest try. I found something called "UTF-8 without BOM" on the internet. Still doesn't work.
Set StreamUnixUtf = CreateObject("ADODB.Stream")
StreamUnixUtf.Type = 1
StreamUnixUtf.Mode = 3
StreamUnixUtf.Open
stream.Position = 3
stream.CopyTo StreamUnixUtf
stream.Flush
stream.Close
StreamUnixUtf.SaveToFile myFileUnixUTF, 2
StreamUnixUtf.Close

提前感谢您的帮助。

【问题讨论】:

标签: excel vba utf-8


【解决方案1】:

TextWrangler (mac) 或 Programmer 的文件编辑器 (PC) 并选择 unix 换行符怎么样 - 当我需要将文件提交到特定系统时使用它...

【讨论】:

  • 嗨。不幸的是,在这种情况下,我不能使用 Excel 以外的任何其他软件。
  • 那么您可能考虑的另一种解决方法是在正确类型的 excel 中打开一个文件,编辑位并保存,但不确定它是否能解决您的问题。
猜你喜欢
  • 1970-01-01
  • 2021-05-15
  • 2013-01-02
  • 2012-02-23
  • 1970-01-01
  • 2012-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多