我具有以下Excel VBA脚本,该脚本在Excel for Mac 2011中用于将Excel文件的所有工作表导出为.csv文件。
Sub save_all_csv()
On Error Resume Next
Dim ExcelFileName As String
ExcelFileName = ThisWorkbook.Name
For Each objWorksheet In ThisWorkbook.Worksheets
ExcelFileNameWithoutExtension = RemoveExtension(ExcelFileName)
CsvFileName = ExcelFileNameWithoutExtension & "__" & objWorksheet.Name & ".csv"
Application.DisplayAlerts = False
objWorksheet.SaveAs Filename:="data:storage:original_excel:" & CsvFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True
Next
Application.DisplayAlerts = False
Application.Quit
End Sub
Function RemoveExtension(strFileName As String)
strFileName = Replace(strFileName, ".xlsx", "")
strFileName = Replace(strFileName, ".xls", "")
RemoveExtension = strFileName
End Function
问题是它们另存为Western Mac OS Roman],我无法通过PHP将其转换为UTF-8,所以我想让VBA在第一个文件中以UTF-8格式保存这些文件地点。
[我已经找到了一些通过Stream对象并使用CreateObject从VBA保存文本的解决方案,但是它是apparently not possibile on the Mac to use CreateObject to write directly to files。
如何使用Excel for Mac 2011将工作表另存为UTF-8格式的CSV文件?
我具有以下Excel VBA脚本,我在Mac 2011的Excel中使用该脚本将Excel文件的所有工作表导出为.csv文件。 Sub save_all_csv()错误继续恢复下一个ExcelFileName ...
我有同样的问题,最终只写了一个例程编码为utf-8
我认为您必须自己进行文件创建是正确的,而且我很确定您不能使用CreateObject制作流。但是,您可能想研究使用“打开”,“写入”等(很多示例,但 here's one)。首先,我将做一个很小的实验,只是为了检查最终的编码方式。
我不知道这是否适用于Mac 2011的Excel,但是对于较新的版本,只需使用FileFormat:=xlCSVUTF8
,它将文件保存为UTF-8。