【问题标题】:Whatsapp .txt file chat into original whatsapp formatWhatsapp .txt文件聊天成原始whatsapp格式
【发布时间】:2022-02-19 16:48:52
【问题描述】:

我有 .txt 文件格式的 whatsapp 聊天。我希望它转换为原始的 whatsapp 格式(即 whatsapp 原始界面)。 输入为.txt文件

例子:

12/11/2014, 12:22 PM - John: Hi Stacy
12/11/2014, 12:22 PM - John: :)
13/11/2014, 2:59 AM - John: How are you?
13/11/2014, 2:59 AM - John: Are u home?
13/11/2014, 8:09 AM - Stacy: Hi John
13/11/2014, 8:10 AM - Stacy: yeah I am good
13/11/2014, 8:10 AM - Stacy: and home too
13/11/2014, 9:14 PM - John: ok
16/11/2014, 4:14 PM - Stacy: how are you?
16/11/2014, 4:16 PM - John: I am good too
16/11/2014, 4:16 PM - John: See u tmrw at work
16/11/2014, 4:16 PM - John: :)
16/11/2014, 4:24 PM - Stacy: yeah ok

现在,我想要一个 Word 文档中的输出,其界面与 whatsapp 的界面相似。

[即左侧的 John 和右侧的 Stacy 的所有聊天]

我尝试通过将此 .txt 文件导入 excel 然后在 word 中编辑来做到这一点。但这没有用。

要求的输出格式:

Please click here to view the required output word format (与whatsapp格式非常相似)

这就是我所做的:

1) 我从 .txt 文件中导入了 excel 中的数据。

2) 我使用 python 代码将该 txt 格式转换为 excel 文件 Please click here to view that file

3) 然后我将其复制到 .doc 文件并添加了边框

4) 现在我删除了输出边框。这就是我在第一个链接中附加的格式的方式。

我面临的问题是文本不存在的地方,我需要手动转到该单元格并选择“无边框”。我有1000个这样的。

无论如何我可以通过编程方式做到这一点吗?

可以使用 Word 或 Excel VBA 完成某些操作吗?

【问题讨论】:

  • 欢迎来到 StackOverflow。请花点时间阅读help center 中关于如何在此处提问的指南。您需要缩小您的问题范围,展示您尝试过的代码并描述该代码如何不起作用。
  • @Cindy Meister:请看编辑
  • 请对其进行格式化,使其易于阅读——您需要帮助,您就可以完成工作......
  • 我认为 Java 标记不适合这里。另外,我认为您可能只专注于一种语言,因为我们无法完全按照您想要的方式完成工作。运行 VBA 代码时遇到什么异常?那里有什么失败?阅读SO Asking Guide 会很有用
  • 您在代码中定位的表在哪里?

标签: vba ms-word


【解决方案1】:

如果您已经有如图所示的表格,您可以做的是删除所有边界并运行以下代码。

Sub demo1()
With ActiveDocument.Range
Dim oCell As Cell
Dim oRow As Row
'remove all boarders before executing this code
    For Each oRow In .Tables(1).Rows
        For Each oCell In oRow.Cells
            If Not oCell.Range.Text = Chr(13) & Chr(7) Then
                Set rng = oCell.Range
                With rng
                    With .Borders(wdBorderTop)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderLeft)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderBottom)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                    With .Borders(wdBorderRight)
                        .LineStyle = Options.DefaultBorderLineStyle
                        .LineWidth = Options.DefaultBorderLineWidth
                        .Color = Options.DefaultBorderColor
                    End With
                End With
            End If
        Next oCell
    Next oRow
End With
End Sub

【讨论】:

  • 海拉胡尔。这不是确切的 o/p,但我从你的代码中得到了这个想法,我想我可以使用你的代码继续前进。非常感谢:)
  • 在 SO 上,很少有人能够理解你想要什么。您将不得不解决他们提供的解决方案。
猜你喜欢
  • 1970-01-01
  • 2019-09-14
  • 1970-01-01
  • 2016-08-17
  • 2021-01-16
  • 2013-06-02
  • 2021-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多