Пример #1
0
 public static void AddBlock(Block block, Docx.DocX doc)
 {
     if (block is Paragraph)
     {
         Paragraph p = (Paragraph)block;
         FlowDocumentExporter.AddParagraph(p, doc);
     }
     else if (block is List)
     {
         List list = (List)block;
         AddList(list, doc);
     }
 }
Пример #2
0
        public void ExportToWord(Docx.DocX doc)
        {
            FlowDocument flowDoc = new FlowDocument(Model.Connection);

            flowDoc.id = Model.FlowDocumentId;
            flowDoc.Load();

            FlowDocumentViewModel vm = new FlowDocumentViewModel(flowDoc, DialogOwner);

            foreach (WinDoc.Block block in vm.Document.Blocks)
            {
                if (block is WinDoc.Paragraph)
                {
                    FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc);
                }
            }
        }
Пример #3
0
        public void ExportToWord(Docx.DocX doc)
        {
            // Format title page of the document.
            Xceed.Document.NET.Paragraph p = doc.InsertParagraph();
            p.Append("\n\n" + Model.Name);
            p.StyleId = "Title";

            if (!string.IsNullOrWhiteSpace(Model.Subtitle))
            {
                p = doc.InsertParagraph();
                p.Append(Model.Subtitle);
                p.StyleId = "Subtitle";
            }
            if (!string.IsNullOrWhiteSpace(Model.Author))
            {
                p = doc.InsertParagraph();
                p.Append("\n\n" + Model.Author);
                p.StyleId = "Subtitle";
            }
            p.InsertPageBreakAfterSelf();

            // Insert copyright page.
            if (Model.FlowDocumentId.HasValue)
            {
                FlowDocument copyrightFd = new FlowDocument(Model.Connection);
                copyrightFd.id = Model.FlowDocumentId.Value;
                copyrightFd.Load();

                FlowDocumentViewModel copyrightVm = new FlowDocumentViewModel(copyrightFd, DialogOwner);

                foreach (WinDoc.Block block in copyrightVm.Document.Blocks)
                {
                    if (block is WinDoc.Paragraph)
                    {
                        FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc);
                    }
                }

                p.InsertPageBreakAfterSelf();
            }

            // Insert eBook table of contents.

            // This doesn't make sense to me. Xceed's documentation says "A key-value dictionary where the key is a TableOfContentSwitches
            // and the value is the parameter of the switch."
            // I have no idea what the string values are supposed to be. Empty strings seem to work.
            Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string> tocParams = new Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string>();

            tocParams[Xceed.Document.NET.TableOfContentsSwitches.H] = ""; // TOC entries are clickable hyperlinks.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.N] = ""; // Omits page numbers.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.Z] = ""; // Hides tab leader and page numbers...?
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.U] = ""; // Uses the applied paragraph outline level...?
            Xceed.Document.NET.TableOfContents toc = doc.InsertTableOfContents("Table of Contents", tocParams);
            doc.Paragraphs.Last().InsertPageBreakAfterSelf();

            for (int i = 0; i < Chapters.Count; i++)
            {
                ChapterViewModel chapter = Chapters[i];
                chapter.ExportToWord(doc);
            }
        }
Пример #4
0
        public void ExportToWord()
        {
            IExportToWordDocument item = SelectedTreeViewItem as IExportToWordDocument;

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "Word Document (*.docx)|*.docx";
            bool?result = saveFileDialog.ShowDialog();

            if (!result.Value)
            {
                return;
            }

            var templates = FileBrowserViewModel.Files.Where(i => i.Model.FileType == FileBlob.FILE_TYPE_TEMPLATE).ToList();

            if (templates.Count > 0)
            {
                FileBlobViewModel defaultTemplate = templates.SingleOrDefault(i => i.Model.id == Model.DefaultTemplateId);

                SelectDocTemplateDialog dialog = new SelectDocTemplateDialog(DialogOwner, templates, defaultTemplate);
                result = dialog.ShowDialog();
                if (result.HasValue && result.Value)
                {
                    defaultTemplate = dialog.SelectedTemplate;
                    string templatePath = null;

                    // Save selected template as default.
                    if (defaultTemplate != null)
                    {
                        Model.DefaultTemplateId = defaultTemplate.Model.id;
                        Model.Save();

                        // Save template to a temp file.
                        templatePath = Path.GetTempFileName();
                        defaultTemplate.Model.ExportToFile(templatePath);
                    }

                    FlowDocumentExporter.ExportItem(item, saveFileDialog.FileName, templatePath);

                    if (templatePath != null)
                    {
                        File.Delete(templatePath);
                    }

                    MessageBoxResult msgResult = MessageBox.Show("Export complete. Open file now?", "Export Completed", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (msgResult == MessageBoxResult.Yes)
                    {
                        Process.Start(new ProcessStartInfo(saveFileDialog.FileName)
                        {
                            UseShellExecute = true
                        });
                    }
                }
            }
            else
            {
                FlowDocumentExporter.ExportItem(item, saveFileDialog.FileName, null);
                MessageBoxResult msgResult = MessageBox.Show("Export complete. Open file now?", "Export Completed", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (msgResult == MessageBoxResult.Yes)
                {
                    Process.Start(new ProcessStartInfo(saveFileDialog.FileName)
                    {
                        UseShellExecute = true
                    });
                }
            }
        }