如何使用Excel for Mac 2011将工作表以UTF-8格式保存为CSV文件? [英] How to save worksheets as CSV files in UTF-8 format with Excel for Mac 2011?

查看:868
本文介绍了如何使用Excel for Mac 2011将工作表以UTF-8格式保存为CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 Excel VBA 脚本,用于Mac 2011的 Excel ,将Excel文件的所有工作表导出到.csv文件。

I have the following Excel VBA script which I use in Excel for Mac 2011 to export all the worksheets of an Excel file to .csv files.

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格式保存这些文件。

The problem is that they save as Western Mac OS Roman which I can't get to convert to UTF-8 via PHP, so I would like to have VBA save these files in UTF-8 format in the first place.

我有找到了一些通过Stream对象从VBA保存文本的解决方案,并使用 CreateObject 但它是的70420 / how-can-i-install-use-scripting-filesystemobject-in-excel-2010-for-mac / 4670622#4670622>。

I've found some solutions for saving text from VBA via a Stream object and with CreateObject but it's apparently not possibile on the Mac to use CreateObject to write directly to files.

如何使用Excel for Mac 2011将工作表以UTF-8格式保存为CSV文件?

推荐答案

我认为你是对的,你必须自己做文件创建,我相信你不能使用CreateObject来制作流。但是,您可能需要研究使用Open,Write等(很多例子,但这里是一个)。首先我会做一个非常小的实验,只是为了检查最终的编码。

I think you're right that you'll have to do the file creation yourself, and I'm quite sure you can't use CreateObject to make streams. However, you may want to look into using Open, Write etc (lots of examples around, but here's one). I'd make a very small experimental one first, just to check what encoding that ends up with, though.

Chris

这篇关于如何使用Excel for Mac 2011将工作表以UTF-8格式保存为CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆