如何使用C#.NET(4)明智地分割word文件页面并打开xml sdk 2.0? [英] how to split a word file page wise using C#.NET(4) and open xml sdk 2.0?

查看:52
本文介绍了如何使用C#.NET(4)明智地分割word文件页面并打开xml sdk 2.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用C#.net和开放XML SDK(2.0)编写了我的应用程序.我已经使用开放XML标签将Word文件按段和按段进行拆分了,但是我找不到关于明智地将Word文件页面拆分的任何信息. br/>
请引导我解决此问题.

Hi All,

I have my application written using C#.net and open XML SDK(2.0).I have splitted the word file paragraph wise and section wise using open XML tags.But i could not find anything about split a word file page wise...

Pleas Guide me get out of this issue.

推荐答案

这里 [ ^ ]是VB方式,您必须将其更改为C#.

Here[^] is the VB way, you have to change it to C#.

Dim WordApp As New Word.Application
       Dim BaseDoc As Word.Document
       Dim DestDoc As Word.Document
       Dim intNumberOfPages As Integer
       Dim intNumberOfChars As String
       Dim intPage As Integer

       'Word Constants
       Const wdGoToPage = 1
       Const wdStory = 6
       Const wdExtend = 1
       Const wdCharacter = 1

       'Show WordApp
       WordApp.ShowMe()

       'Load Base Document
       BaseDoc = WordApp.Documents.Open(Filename)
       BaseDoc.Repaginate()

       'Loop through pages
       intNumberOfPages = BaseDoc.BuiltInDocumentProperties("Number of Pages").value
       intNumberOfChars = BaseDoc.BuiltInDocumentProperties("Number of Characters").value

       For intPage = 1 To intNumberOfPages
           If intPage = intNumberOfPages Then
               WordApp.Selection.EndKey(wdStory)
           Else
               WordApp.Selection.GoTo(wdGoToPage, 2)
               Application.DoEvents()

               WordApp.Selection.MoveLeft(Unit:=wdCharacter, Count:=1)
           End If

           Application.DoEvents()

           WordApp.Selection.HomeKey(wdStory, wdExtend)
           Application.DoEvents()

           WordApp.Selection.Copy()
           Application.DoEvents()

           'Create New Document
           DestDoc = WordApp.Documents.Add
           DestDoc.Activate()
           WordApp.Selection.Paste()
           DestDoc.SaveAs(NewFileName & intPage.ToString & ".doc")
           DestDoc.Close()
           DestDoc = Nothing

           WordApp.Selection.GoTo(wdGoToPage, 2)
           Application.DoEvents()

           WordApp.Selection.HomeKey(wdStory, wdExtend)
           Application.DoEvents()

           WordApp.Selection.Delete()
           Application.DoEvents()
       Next

       BaseDoc.Close(False)
       BaseDoc = Nothing

       WordApp.Quit()
       WordApp = Nothing
   End Sub


这篇关于如何使用C#.NET(4)明智地分割word文件页面并打开xml sdk 2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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