excel - Google 文档导出带双引号的 CSV

标签 excel csv google-docs

我有一个需要导出的 Google 电子表格,并且每个字段都包含在双引号“字段”中,但目前它不会执行此操作。

有没有一种简单的方法可以实现这一点,而无需手动编辑数百行?

最大

最佳答案

您可以从 Excel 使用适当的宏,如下所示:

Sub QuoteCommaExport()

   ' Dimension all variables.

   Dim DestFile As String

   Dim FileNum As Integer

   Dim ColumnCount As Integer

   Dim RowCount As Integer



   ' Prompt user for destination file name.

   DestFile = InputBox("Enter the destination filename" & Chr(10) & "(with complete path):", "Quote-Comma Exporter")



   ' Obtain next free file handle number.

   FileNum = FreeFile()



   ' Turn error checking off.

   On Error Resume Next



   ' Attempt to open destination file for output.

   Open DestFile For Output As #FileNum



   ' If an error occurs report it and end.

   If Err <> 0 Then

      MsgBox "Cannot open filename " & DestFile

      End

   End If



   ' Turn error checking on.

   On Error GoTo 0



   ' Loop for each row in selection.

   For RowCount = 1 To Selection.Rows.Count



      ' Loop for each column in selection.

      For ColumnCount = 1 To Selection.Columns.Count



         ' Write current cell's text to file with quotation marks.

         Print #FileNum, """" & Selection.Cells(RowCount, ColumnCount).Text & """";



         ' Check if cell is in last column.

         If ColumnCount = Selection.Columns.Count Then

            ' If so, then write a blank line.

            Print #FileNum,

         Else

            ' Otherwise, write a comma.

            Print #FileNum, ";";

         End If

      ' Start next iteration of ColumnCount loop.

      Next ColumnCount

   ' Start next iteration of RowCount loop.

   Next RowCount



   ' Close destination file.

   Close #FileNum

End Sub

关于excel - Google 文档导出带双引号的 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7272663/

相关文章:

excel - 将单元格范围操作的输出获取到一个单元格中

mysql - 为什么将脚本加载到 mysql 时会出现此错误?

java - 在java中读取流文件

javascript - 通过 Google Apps 脚本对 Google 文档中的字符串进行文本格式设置

google-docs - 在 asp.net 应用程序中使用 google docs

excel - 根据列和行标题搜索值

python - 如何使用 pandas 写入 Excel 文档的中间

vba - 使用部分变量名称检索最后修改的文件

python - GAE Python - 如何将 csv.writer 的结果附加到电子邮件中?

google-apps-script - 如何对 Google 文档/云端硬盘文档中的标题进行编号?