文档格式不应更改。除了单词顺序没有任何变化。
文档 :
Word1 word2 word3 word2... -- END OF LINE OR PARAGRAPH
Word5 word1 word5 word4.....
倒车后应该如下
1droW 2drow 3drow 2drow... -- END OF LINE OR PARAGHRAPH
5droW 1drow 5drow 4drow.....
我已经有了这个代码来逐字逐句,但我不知道如何在不丢失格式的情况下进行更改。
string RT = "";
Word.Application wordObject = new Word.Application();
wordObject.Visible = false;
Word.Document docs = wordObject.Documents.Open(@"D:\ELAHE (J)\a.docx");
String strLine;
bool bolEOF = false;
docs.Characters[1].Select();
int index = 0;
do {
object unit = Word.WdUnits.wdWord;
object count = 1;
wordObject.Selection.MoveEnd(ref unit, ref count);
wordObject.Selection.InsertBefore("");
strLine = wordObject.Selection.Text;
RT += ++index + " - " + strLine + "\r\n";
object direction = Word.WdCollapseDirection.wdCollapseEnd;
wordObject.Selection.Collapse(ref direction);
if (cnt++ > 100) break;
if (wordObject.Selection.Bookmarks.Exists(@"\EndOfDoc")) bolEOF = true;
} while (!bolEOF);
docs.Close();
wordObject.Quit();
docs = null;
wordObject = null;