首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Excel中为CSV选择导出列

在Excel中为CSV选择导出列
EN

Stack Overflow用户
提问于 2018-04-12 10:42:38
回答 1查看 29关注 0票数 1

我发现了下面的代码,它解析PPT文件的文本并将其转储到CSV文件中。

代码语言:javascript
复制
 Sub ExportTextToCSV()

  Dim oPres As Presentation
  Dim oSlides As Slides
  Dim oSld As Slide         'Slide Object
  Dim oShp As Shape         'Shape Object
  Dim iFile As Integer      'File handle for output
  Dim sTempString As String

  Dim PathSep As String
  Dim Quote As String
  Dim Comma As String
  iFile = FreeFile          'Get a free file number

  #If Mac Then
    PathSep = ":"
  #Else
    PathSep = "\"
  #End If

  Quote = Chr$(34)
  Comma = ","

  Set oPres = ActivePresentation
  Set oSlides = oPres.Slides

  'Open output file
  ' NOTE:  errors here if original PPT file hasn't been saved
  Open oPres.Path & PathSep & "ParsedText1.csv" For Output As iFile

  For Each oSld In oSlides    'Loop thru each slide
    For Each oShp In oSld.Shapes                'Loop thru each shape on slide

      'Check to see if shape has a text frame and text
      If oShp.HasTextFrame And oShp.TextFrame.HasText Then
          sTempString = sTempString & Quote & oShp.TextFrame.TextRange.Text & Quote & Comma
      End If

    Next oShp

    ' print the result to file:
    Print #iFile, sTempString
    sTempString = ""

  Next oSld

  'Close output file
  Close #iFile

End Sub

当我运行它时,它会将文本转储到CSV文件的A列中。是否有任何修改可以让我选择将其转储到哪一列?例如,如果我想把它转储到D列中,我应该做什么修改?任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-12 10:48:00

对于列D,在字符串之前写3个逗号。

因此,来自:

代码语言:javascript
复制
sTempString = sTempString & Quote & oShp.TextFrame.TextRange.Text & Quote & Comma

写入:

代码语言:javascript
复制
sTempString = sTempString & ",,," & Quote & oShp.TextFrame.TextRange.Text & Quote & Comma
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49794482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档