示例#1
0
 private void OnClick_SortParagraphs(object sender, RoutedEventArgs e)
 {
     Word.ListParagraphs list = WordDocument.ListParagraphs;
     MessageBox.Show(list.Count.ToString());
 }
        static void Main(string[] args)
        {
            string        finalHTML;
            List <string> listString = new List <string>();
            object        True       = true;

            Word.Application app      = new Word.Application();
            Word.Document    doc      = new Word.Document();
            string           fileName = @"D:\Programming\C#\Word To Markup Converter\hello world.docx";

            doc = app.Documents.Open(fileName, Type.Missing, True);

            //foreach (Word.Paragraph para in doc.Paragraphs)
            //{
            //    para.Range.Copy();
            //    stripClasses(Clipboard.GetText(TextDataFormat.Html));
            //}
            Word.ListParagraphs listpara = doc.ListParagraphs;
            IEnumerator         ienum    = doc.ListParagraphs.GetEnumerator();
            List <Tuple <string, Word.WdListType, int> > items = new List <Tuple <string, Word.WdListType, int> >();

            while (ienum.MoveNext())
            {
                Word.Range r = ((Word.Paragraph)ienum.Current).Range;
                items.Add(new  Tuple <string, Word.WdListType, int>(r.Text, r.ListFormat.ListType, r.ListFormat.ListLevelNumber));
            }

            items.Reverse();
            if (items.Count > 0)
            {
                listString = createList(items);
            }
            doc.SelectAllEditableRanges();
            doc.Range().Copy();

            string returnHTMLText = null;



            if (Clipboard.ContainsText(TextDataFormat.Html))
            {
                Console.WriteLine("html");
                returnHTMLText = Clipboard.GetText(TextDataFormat.Html);
                //Console.WriteLine(returnHTMLText);
                stripClasses(returnHTMLText, listString);
            }
            else
            {
                Console.WriteLine("no html");
                //Console.WriteLine(doc.);
                //returnHTMLText = Clipboard.GetText(TextDataFormat.Html);
            }

            doc.Close();
            app.Quit();
            Console.WriteLine("closed");
            while (true)
            {
                ;
            }
        }