gpt4 book ai didi

php - rtf 到 html 列表

转载 作者:行者123 更新时间:2023-11-28 02:01:04 25 4
gpt4 key购买 nike

简要介绍一下背景,我有很多笔记,我15年前以wpd格式打字,大约10年前,我将它们转换为rtf格式,现在我想将它们转换为html。我看过的所有 php 示例都使用非常基本的 html。我想采用的方式涉及嵌套列表。

http://dl.dropbox.com/u/47490038/ech.rtf

https://dl.dropbox.com/u/47490038/notes/index.html

到目前为止,我已经使用了下面的宏,从 rtf 到 txt,但是现在 php 部分超出了我的范围,其中一些可以通过计算每行开头的制表符或空格来完成,请参阅上面的 url 以获得所需的输出。我可以稍后添加其他样式。

我愿意接受有关如何执行此操作的建议,即使它是我不熟悉的语言。即使是宏,我也不是很满意,我希望能够在 word 之外选择一个文件夹或文件,考虑到我有 100 个要转换,甚至可能是拖放的东西。

            Sub ChangeDocsToTxtOrRTFOrHTML()
'with export to PDF in Word 2007
Dim fs As Object
Dim oFolder As Object
Dim tFolder As Object
Dim oFile As Object
Dim strDocName As String
Dim intPos As Integer
Dim locFolder As String
Dim fileType As String
On Error Resume Next
locFolder = InputBox("Enter the folder path to RTFs", "File Conversion", "C:\myDocs")
Select Case Application.Version
Case Is < 12
Do
fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML", "File Conversion", "TXT"))
Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML")
Case Is >= 12
Do
fileType = UCase(InputBox("Change DOC to TXT, RTF, HTML or PDF(2007+ only)", "File Conversion", "TXT"))
Loop Until (fileType = "TXT" Or fileType = "RTF" Or fileType = "HTML" Or fileType = "PDF")
End Select
Application.ScreenUpdating = False
Set fs = CreateObject("Scripting.FileSystemObject")
Set oFolder = fs.GetFolder(locFolder)
Set tFolder = fs.CreateFolder(locFolder & "Converted")
Set tFolder = fs.GetFolder(locFolder & "Converted")
For Each oFile In oFolder.Files
Dim d As Document
Set d = Application.Documents.Open(oFile.Path)
strDocName = ActiveDocument.Name
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 1)
ChangeFileOpenDirectory tFolder
Select Case fileType
Case Is = "TXT"
strDocName = strDocName & ".txt"
ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatText
Case Is = "RTF"
strDocName = strDocName & ".rtf"
ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatRTF
Case Is = "HTML"
strDocName = strDocName & ".html"
ActiveDocument.SaveAs FileName:=strDocName, FileFormat:=wdFormatFilteredHTML
Case Is = "PDF"
strDocName = strDocName & ".pdf"

' *** Word 2007 users - remove the apostrophe at the start of the next line ***
'ActiveDocument.ExportAsFixedFormat OutputFileName:=strDocName, ExportFormat:=wdExportFormatPDF

End Select
d.Close
ChangeFileOpenDirectory oFolder
Next oFile
Application.ScreenUpdating = True
End Sub

我意识到我问了很多,任何指导、建议、帮助、代码都将不胜感激。

最佳答案

在我看来,您的源文档是 RTF 格式的,但它们不使用任何基于 RTF 的嵌套。是对的吗?例如,“2 级”项目符号与“1 级”项目符号的不同不是因为 RTF 中的任何内容,而是因为有人添加了更多空格?

例如,在文件中我看到很多\par 标记,但没有任何迹象表明嵌套。所以你有一个\par\ul block (例如在“原始教堂”中),然后直接进入 A.1 小节,除了一个制表符和一个祈祷(可以这么说!)

鉴于此,您不能过分依赖 RTF。我的建议是删除所有 RTF 标记,留下一个文档,其布局仅通过使用空格和制表符定义。然后,处理每一行(Perl 对此很擅长)并从空格数和前导组合的使用中计算出来,就像新列表开始一样。并相应地插入标签。

它会很难看,但这是糟糕标记的代价。

关于php - rtf 到 html 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13938471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com