有没有办法从两个现有文档中以编程方式构造一个Open Office文档? [英] Is there a way to programmatically construct an Open Office document from two existing documents?

查看:134
本文介绍了有没有办法从两个现有文档中以编程方式构造一个Open Office文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两份文件,一份用西班牙语,一份用英语(英语是西班牙语原文的翻译版本).我要从这两个文件中创建第三个文档,每个文档在均匀编号的页面上包括西班牙语,而在相对奇数编号的页面上包含相应的英语翻译.

I have two documents, one in Spanish and one in English (the English is a translated version of the original in Spanish). I am creating a third document from the two, which includes the Spanish on each evenly numbered page, and the corresponding English translation on the opposite odd-numbered page.

我正在用尽整个页面的两边,除了一章的末尾(每个新章节都有分页符,因此它可以从页面顶部开始).诚然,为了用尽整个页面,有时文本的某些部分位于下一页 (也就是说,有时在西班牙语的第18页底部出现的英文译本出现在第21页顶部,而不是在第19页的底部.)

I am using up the entire page on both sides except at the end of a chapter (each new chapter gets a page break, so it can start at the top of the page). Admittedly, in order to use up the entire page, there are occasions where portions of the text are on the next page (that is to say, the English translation of what appears at the bottom of page 18 in Spanish on occasion appears at the top of page 21, rather than at the bottom of page 19).

我目前正在手动执行以下操作,以打开所有三个Open Office文档(Spanish.odt,English.odt和SpanishEnglish.odt):

I am currently manually doing the following to accomplish this, with all three Open Office documents open (Spanish.odt, English.odt, and SpanishEnglish.odt):

0) Cut and paste exactly one page of material from Spanish.odt to the next (even-numbered) page of SpanishEnglish.odt
1) Mash the Enter key to move to the next (odd-numbered) page
2) Cut and paste exactly one page of material from English.odt to the next (odd-numbered) page of SpanishEnglish.odt
3) Mash the Enter key to move to the next (even-numbered) page

此外,我会定期(到达本章末尾)插入一个分页符;如果本章的结尾在西班牙英语.odt上的西班牙语或英语页面上都不合适(当然另一种页面不适合),我会减小太长页面的字体大小(从Verdana 10到Verdana) 9)强制将其限制在该页面上,以使各章并排开始(西班牙语在左边/偶数,英语在右边/奇数),而没有任何空白页.

Also, periodically (when the chapter end is reached), I insert a Page Break; if the end of the chapter doesn't fit on one page for either the Spanish or English (while the other does, of course) in SpanishEnglish.odt, I reduce the font size of the too-long page (from Verdana 10 to Verdana 9) to force it to constrain itself to that page, so that the chapters begin side-by-side (Spanish on the left/even, English on the right/odd) without having any blank pages.

-特别是对于大型文档-此过程很快变得非常乏味.有没有办法在C#中以编程方式完成相同的工作?

As you can doubtless imagine -- especially with a large document, which this is -- this procedure gets very tedious very quickly. Is there a way to programmatically accomplish the same thing in C#?

Shujaat Siddiqui,我想你的意思是更改最后几行:

Shujaat Siddiqui, I assume you mean change these last lines:

The Dangerous Pelican Movie
. . .
La película de los pelícanos peligrosos

...对此:

The Dangerous Pelican Movie&&&&
. . .
La película de los pelícanos peligrosos&&&&

...通过添加&&&"到最后一行-Correctomundo?但是在许多情况下,此附加文本(&&&")会将内容推到下一页(一个或多个&"号将流到下一页),不是吗?

...by appending "&&&&" to the last line - Correctomundo? But in many cases this additional text ("&&&&") will push the contents to the next page (one or more of the ampersands will flow onto the following page), no?

推荐答案

有点棘手.我只是想给你基本的想法.

Its bit Tricky. I am trying to give you just the basic idea.

  1. 只需在每页末尾写&& .用英语和西班牙语进行翻译.
  2. 现在使用正则表达式从&&& 中断开文本.就像逐页阅读文档一样.
  1. Just write &&&& at the end of every page. In English doc as well as in Spanish doc.
  2. now use regex to break text from &&&&. Its like reading the doc page by page.

这里是示例代码,只是为了向您提供基本的逻辑.

Here is a sample code just to give you the basic logic.

            string Doc1Read  = //read from english file
            string Doc2Read = // read from Spanish file


                string exp = @"[\w\s\n\r\t\.\(\)\,\[\]\-\;\:\%\@\#]*(?=&&&&)";

                var Doc1matches = Regex.Matches(Doc1Read, exp);
                var Doc2matches = Regex.Matches(Doc2Read, exp);
                for (int i = 0; i < Doc1matches.Count; i++)
                {
                    **// open third document file and write** 

                    Doc1matches[i].Value; // write english version of page i
                    Doc2matches[i].Value; // write spanish version of page i

                }

&&& 用于逐页获取文本.这样,当您使用Doc1matches[i].Value;时,基本上可以得到写在页码 i 上的内容,即{1,2,3 ...}.

&&&& is used to get the text page by page . In this way when you use Doc1matches[i].Value;you basically get what is written on page number i i.e {1,2,3...}.

希望它对您有所帮助.

PS:您还可以使用string.Split("&&&&");&&&& 中断开字符串.并可以实现逻辑.

PS : You can also use string.Split("&&&&"); to break the string from &&&&. and can implement the logic.

这篇关于有没有办法从两个现有文档中以编程方式构造一个Open Office文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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