Пример #1
0
        /*
         * 加载word 文件
         *
         * @param DocumentViewer 显示容器
         *
         * @param DControl ctl 控件信息
         */
        public static void loadWord(CWord cWord, string wordFullFile)
        {
            cWord.clearContent();
            string                xpsFile = wordFullFile;
            XpsDocument           xpsDoc  = new XpsDocument(xpsFile, FileAccess.Read);
            FixedDocumentSequence fds     = xpsDoc.GetFixedDocumentSequence();

            System.Windows.Size size = fds.DocumentPaginator.PageSize;

            foreach (DocumentReference DocRef in fds.References)
            {
                bool          bForceReload = false;
                FixedDocument DocFd        = DocRef.GetDocument(bForceReload);

                foreach (PageContent DocFpPc in DocFd.Pages)
                {
                    FixedPage fp = new FixedPage();
                    fp.SetValue(DockPanel.DockProperty, Dock.Top);
                    fp.Width      = size.Width;
                    fp.Height     = size.Height;
                    fp.Background = System.Windows.Media.Brushes.Red;

                    //FixedPage DocFp = DocFpPc.GetPageRoot(bForceReload);
                    //for (int i = 0; i < DocFp.Children.Count; i++)
                    //{
                    //    UIElement DocFpUiElem = DocFp.Children[i];
                    //    DocFp.Children.Remove(DocFpUiElem);
                    //    fp.Children.Add(DocFpUiElem);
                    //}
                    cWord.insertContent(fp);
                }
            }
            xpsDoc.Close();//这个地方需要注意关闭,否则的话会出现莫名其妙的错误
        }