如何通过页面将word文件拆分成多个word文件(c#) [英] how to split a word file into several word files by pages (c#)

查看:424
本文介绍了如何通过页面将word文件拆分成多个word文件(c#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个十页的word文件。我想把这个单词分成十个小单词文件?



有没有办法做到这一点?它需要使用c#。不是VBA!



我找到了一些vba解决方案,但我不熟悉vba。有什么方法可以将vba翻译成c#????



VBA



使用:

there is a ten pages word file. I want to split this word into ten small words file?

is there any method to do this? it is required to use c# . not VBA!

I find some vba solutions, but i am not familiar with vba. is there any method to translate vba to c#????

VBA

Use:

' splitter Macro 
' Macro created 16-08-98 by Doug Robbins to save each page of a document 
' as a separate file with the name Page#.DOC 
' modified 28-09-2010 to use filename of the last 9 digits of the first paragraph
Dim Counter As Long, Source As Document, Target As Document 
Dim Docname As Range 
Set Source = ActiveDocument 
Selection.HomeKey Unit:=wdStory 
Pages = Source.BuiltInDocumentProperties(wdPropertyPages) 
Counter = 0 
While Counter < Pages 
    Counter = Counter + 1 
    Docname = "Page" & Format(Counter) 
    Source.Bookmarks("\Page").Range.Cut 
    Set Target = Documents.Add 
    Target.Range.Paste 
    Set Docname = Target.Range.Paragraphs(1).Range 
    Docname.Start = Docname.End - 10 
    Docname.End = Docname.End - 1 
    Target.SaveAs filename:=Docname.Text 
    Target.Close 
Wend

推荐答案

从VBA转换为C#的方法?是的,是的,它被称为良好的努力(它真的不那么难)



这是一个关于SO的类似问题的链接,可以帮助你开始使用对象Word中的文档操作模型等 - 有些东西很简单,ymmv按页面拆分



http://stackoverflow.com/questions/11754608/how-to-split-pages- word-document-into-separate-files-in-c-sharp [ ^ ]
method to translate from VBA to C# ? yeah, right, its called good hard work (its not that hard really)

Here's a link to a similar question on SO that may help you get started with the Object Model etc for document manipulation in Word - some things are easy, ymmv on splitting by page

http://stackoverflow.com/questions/11754608/how-to-split-pages-of-a-word-document-into-separate-files-in-c-sharp[^]


也有看看这个作为首发,至少得到页数 - 如果你至少可以做到这一点,你知道你的项目设置正确,你正在说话 - 这是一半的战斗





[ ^ ]
also have a look at this as a starter to at least get the number of pages - if you can at least do that, you know your project is set up correctly and you're talking to word - which is half the battle


[^]


hi,



据我所知,它可以直接将VBA转换为C#。但是可以将VBA转换为VB.NET,然后转换为C#。

这种方式看起来有点复杂。


As far as I know,it can;t be convert VBA to C# directly.But it is possible converting VBA to VB.NET, then to C#.
This way seems a little bit complicated.


这篇关于如何通过页面将word文件拆分成多个word文件(c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆