1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
public static int get_Level(Word.WdOutlineLevel wdOutLineLevel)
{
Word.WdOutlineLevel[] allOutlineLevel = new Word.WdOutlineLevel[] { Word.WdOutlineLevel.wdOutlineLevelBodyText, Word.WdOutlineLevel.wdOutlineLevel1, Word.WdOutlineLevel.wdOutlineLevel2, Word.WdOutlineLevel.wdOutlineLevel3, Word.WdOutlineLevel.wdOutlineLevel4, Word.WdOutlineLevel.wdOutlineLevel5, Word.WdOutlineLevel.wdOutlineLevel6, Word.WdOutlineLevel.wdOutlineLevel7, Word.WdOutlineLevel.wdOutlineLevel8, Word.WdOutlineLevel.wdOutlineLevel9 };
for (int i = 0; i < allOutlineLevel.Length; i++)
{
if (allOutlineLevel[i] == wdOutLineLevel)
{
return i;
}
}
return 0;
}
public void test_WORD()
{
try
{
Word.Style[] tabStyle = new Word.Style[] { null, null, null, null, null, null, null, null, null, null };
Word.Application myWordApp = toolBox.Wd_createProcess();
Word.Document oDoc;
// Open src Word document
oDoc = myWordApp.Documents.Open(this.textBoxPathSrc.Text); // c:\test_src.doc
foreach (Word.Paragraph myParaph in oDoc.Paragraphs)
{
int level = toolBox.get_Level(myParaph.OutlineLevel);
dynamic style = myParaph.get_Style();
if (tabStyle[level] == null)
{
tabStyle[level] = (Word.Style)style;
}
}
oDoc.Close(oFalse, oMissing, oMissing);
toolBox.COM_releaseObject(oDoc);
oDoc = myWordApp.Documents.Open(this.textBoxPathDest.Text); // c:\test_out.doc
foreach (Word.Paragraph myParaph in oDoc.Paragraphs)
{
int level = toolBox.get_Level(myParaph.OutlineLevel);
object myStyle = tabStyle[level];
myParaph.set_Style(ref myStyle);
}
oDoc.Close(oFalse, oMissing, oMissing);
toolBox.COM_releaseObject(oDoc);
myWordApp.Quit(oFalse, oMissing, oMissing);
toolBox.COM_releaseObject(myWordApp);
}
catch (Exception err)
{
MessageBox.Show(toolBox.format_error(err));
}
} |
Partager