代码之家  ›  专栏  ›  技术社区  ›  Holograham

将Word文档拆分为较小的文档

  •  3
  • Holograham  · 技术社区  · 16 年前

    我希望用户能够上传Word文档,然后我的程序将文档解析为单独的Word文档。问题是拆分需要手动进行,因为所有Word文档的格式都不相同。我最初的想法是,在用户上传之前,用户用一个开始和结束标记(某种程度上可能是注释)来标记这些部分,然后我的程序可以解析这些部分,并将它们分割成单独的文档。(这也需要适用于.doc和.docx,因此需要一个通用的解决方案)

    Ex. Input:

    DOC1

    第一章

    废话连篇

    第2章

    废话

    结束DOC1

    输出:

    DOC1

    第一章

    废话连篇

    结束DOC1

    文件2

    第2章

    胡说八道

    终端DOC2

    有什么想法吗?我已经为此挣扎了一段时间了

    5 回复  |  直到 9 年前
        1
  •  4
  •   Paul Kohler    16 年前

    你想做的是不平凡的!我在文档处理方面做了相当多的工作,也就是说,如果您现在使用的是docx,那么由于支持库的缘故,这并不算太糟糕,请参见:

    http://openxmldeveloper.org/

    旧版本会变得更困难,您需要为此提供一个库,或者按照建议使用宏。

    “程序”是网站吗?如果是这样,确保你 不要 使用COM互操作!

        2
  •  0
  •   No Refunds No Returns    16 年前

    我想说,您最好的办法是研究VSTO或VBA宏来完成这项工作。无论文档是什么版本,这两者都将使您能够完全访问对象模型。

        3
  •  0
  •   bryanjonker    16 年前

    HTML传输可能有帮助。它是一个非常老的软件,而且非常昂贵,从最初的搜索来看,它可能不再受支持。但是,它确实能够获取一个单词文档,并将其拆分为更小的部分(当然,它也将其转换为HTML)。可能是要调查的。谷歌“HTML传输”的更多研究和免费演示。

        4
  •  0
  •   John Laffoon    16 年前

    我很成功 Aspose.Words 用于文档操作和生成。

        5
  •  0
  •   Saad    9 年前

    用于将文件拆分为子文档的VBA宏

    子更新文档()

        Application.ScreenUpdating = False
        Dim strFolder As String, strFile As String, wdDoc As Document
        strFolder = GetFolder
        If strFolder = "" Then Exit Sub
        strFile = Dir(strFolder & "\*.doc", vbNormal)
        While strFile <> ""
            Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile,      AddToRecentFiles:=False, Visible:=False)
            With wdDoc
                'Call your other macro or insert its code here
                'BreakOnSection
                wdDoc.Activate
    
            ActiveDocument.ActiveWindow.View.Type = wdOutlineView
                Selection.WholeStory
            Selection.Copy
                ActiveDocument.Subdocuments.AddFromRange Range:=Selection.Range
                ActiveDocument.SaveAs "C:\Data\Split\" & ActiveDocument.Name
    
                ActiveDocument.Close SaveChanges:=True
        End With
        strFile = Dir()
        Wend
        Set wdDoc = Nothing
        Application.ScreenUpdating = True
    End Sub
    
    Function GetFolder() As String
        Dim oFolder As Object
        GetFolder = ""
        Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0,     
    
    "Choose a folder", 0)
        If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
        Set oFolder = Nothing
    End Function
    
    推荐文章