Represents a document.
Наследование: Container, IDisposable
Пример #1
0
    private BaseConverter createForParagraph( DocX doc, Paragraph paragraph ) {
      var isList = paragraph.IsListItem;
      if( isList ) return createConverterForList( doc, paragraph );

      var type = Type.GetType( "DocXToMarkdown.Converter." + _converters[paragraph.StyleName] );
      return (BaseConverter)Activator.CreateInstance( type, new object[] { doc, paragraph } );
    }
Пример #2
0
 private void _Create(string file, IEnumerable<OXmlElement> elements)
 {
     using (_document = DocX.Create(file))
     {
         foreach (OXmlElement element in elements)
         {
             switch (element.Type)
             {
                 //case zDocXElementType.BeginParagraph:
                 //    _paragraph = _document.InsertParagraph();
                 //    break;
                 //case zDocXElementType.EndParagraph:
                 //    _paragraph = null;
                 //    break;
                 case OXmlElementType.Paragraph:
                     _paragraph = _document.InsertParagraph();
                     break;
                 case OXmlElementType.Text:
                     AddText(element);
                     break;
                 case OXmlElementType.Line:
                     AddLine();
                     break;
                 case OXmlElementType.Picture:
                     AddPicture(element);
                     break;
             }
         }
         _document.Save();
     }
 }
Пример #3
0
        private string CreateDoc( ) {
            var fileName = Seged.Seged.CreateFileName(versenyAdatok.VersenysorozatAzonosito, versenyAdatok.Azonosito,
                DokumentumTipus.Startlista.BeiroLap);
                
            document = DocX.Create( fileName );
            document.MarginBottom = 10;
            document.AddHeaders( );

            #region Cimbekezdes
            var titleFormat = new Formatting {Size = 10D, Position = 1, Spacing = 5, Bold = true};
            var header = document.Headers.odd;
            var title = header.InsertParagraph();

            title.Append( Feliratok.HeadLine.Beirolap);
            title.Alignment = Alignment.center;
            titleFormat.Size = 10D;
            title.AppendLine( Feliratok.Tulajdonos );
            title.AppendLine( );
            title.Bold( );
            titleFormat.Position = 12;
            #endregion

            VersenyTablazat( );
            InduloTablazat( );
            EredmenyTablazat( );
            AlairasTablazat( );

            try { document.Save( ); } catch( System.Exception ) { MessageBox.Show( "A dokumentum meg van nyitva!", "Nevezési lista", MessageBoxButton.OK, MessageBoxImage.Error ); }
            return fileName;
        }
Пример #4
0
 private void AssureUpdateField(DocX document)
 {
     if (document.settings.Descendants().Any(x => x.Name.Equals(DocX.w + "updateFields"))) return;
     
     var element = new XElement(XName.Get("updateFields", DocX.w.NamespaceName), new XAttribute(DocX.w + "val", true));
     document.settings.Root.Add(element);
 }
Пример #5
0
 public BaseConverter( DocX d, Paragraph p ) {
   _paragraph = p;
   _document = d;
   _text = Sanitize( _paragraph.Text );
   CheckHiperlinks();
   CheckPictures();
 }
Пример #6
0
 /// <summary>
 /// Start with filename
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="defaultModules"></param>
 public TemplBuilder(string filename, bool defaultModules = true)
     : this(defaultModules)
 {
     Doc = DocX.Load(filename);
     Doc.SaveAs(Stream);
     Filename = filename;
 }
Пример #7
0
 private static void CreateList(DocX doc)
 {
     var list = doc.AddList("Properly structured and follow all good OOP practices", 0, ListItemType.Bulleted);
     doc.AddListItem(list, "Awesome");
     doc.AddListItem(list, "..Very Awesome");
     doc.InsertList(list);
 }
Пример #8
0
        public FamilyPictureDir(Guid id)
        {
            this.id = id;
            dd = DocX.Create("ttt.docx");

            pa = new Parameters()
            {
                PageHeight = 8.5,
                PageWidth = 5.5,
                MarginLeft = .5,
                MarginRight = .3,
                MarginTop = .5,
                MarginBottom = .3,
                FontSizeName = 18.0,
                FontSize = 14,
            };

            pa.CellWidth = pa.PageWidth - pa.MarginLeft - pa.MarginRight;
            pa.RowHeight = pa.PageHeight - pa.MarginTop - pa.MarginBottom;
            pa.MaxPicHeight = pa.RowHeight * .4;

            dd.PageHeight = Pixels(pa.PageHeight);
            dd.PageWidth = Pixels(pa.PageWidth);
            dd.MarginLeft = Pixels(pa.MarginLeft);
            dd.MarginRight = Pixels(pa.MarginRight);
            dd.MarginTop = Pixels(pa.MarginTop);
            dd.MarginBottom = Pixels(pa.MarginBottom);
        }
Пример #9
0
        public override void MergeField(DocX doc)
        {
            base.MergeField(doc);

            doc.AddCustomProperty(new Novacode.CustomProperty("ProductPart.LabelsPerRoll", this.LabelsPerRoll??0));
            doc.AddCustomProperty(new Novacode.CustomProperty("ProductPart.SoulDiameter", this.SoulDiameter ?? 0));
            doc.AddCustomProperty(new Novacode.CustomProperty("ProductPart.MaxDiameter", this.MaxDiameter ?? 0));
        }
Пример #10
0
        public SeverityIdeaRenderer(DocX wordDocument)
        {
            _wordDocument = wordDocument;

            _documentTagService = new DocumentTagService(new TagEntityRepository());

            _formatting = new FormattingRepository();
        }
        public DefaultDocumentSectionRenderer(DocX _document, IDocumentSubSectionRenderer documentSubSectionRenderer)
        {
            _wordDocument = _document;

            _formatting = new FormattingRepository();

            _documentSubSectionRenderer = documentSubSectionRenderer;
        }
Пример #12
0
        public SeveritySubSectionRenderer(DocX _document, IDocumentIdeaRenderer documentIdeaRenderer)
        {
            _wordDocument = _document;

            _formatting = new FormattingRepository();

            _documentIdeaRenderer = documentIdeaRenderer;
        }
Пример #13
0
 protected override void BeginProcessing()
 {
     this.resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath);
     if (File.Exists(this.resolvedPath))
     {
         this.wordDocument = DocX.Load(this.resolvedPath);
     }
 }
Пример #14
0
 public TemplGraphic Load(DocX doc)
 {
     if (!Loaded)
     {
         Image = doc.AddImage(Data);
         Loaded = true;
     }
     return this;
 }
Пример #15
0
        internal Cell(DocX document, XElement xml)
        {
            this.document = document;
            this.xml = xml;

            XElement properties = xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));

            p = new Paragraph(document, 0, xml.Element(XName.Get("p", DocX.w.NamespaceName)));
        }
       public virtual void MergeField(DocX doc)
       {
           doc.AddCustomProperty(new Novacode.CustomProperty("PPPA.TypeOfMaterial", this.TypeOfMaterial));
           doc.AddCustomProperty(new Novacode.CustomProperty("PPPA.NameOfMaterial", this.NameOfMaterial));
           doc.AddCustomProperty(new Novacode.CustomProperty("PPPA.Color", this.Color));
           doc.AddCustomProperty(new Novacode.CustomProperty("PPPA.Weight", this.Weight ?? 0));
           doc.AddCustomProperty(new Novacode.CustomProperty("PPPA.Adhesive", this.Adhesive));
 		        
       }
Пример #17
0
        internal Hyperlink(DocX document, PackagePart mainPart, XElement i)
            : base(document, i)
        {
            this.type = 0;
            this.id = i.Attribute(XName.Get("id", DocX.r.NamespaceName)).Value;

            StringBuilder sb = new StringBuilder();
            HelperFunctions.GetTextRecursive(i, ref sb);
            this.text = sb.ToString();
        }
Пример #18
0
 private static void CreateHeader(DocX doc)
 {
     string headerText = "SoftUni OOP Game Contest";
     var headerFormat = new Formatting();
     headerFormat.FontFamily = new FontFamily("Tahoma");
     headerFormat.Size = 18D;
     headerFormat.Position = 12;
     var header = doc.InsertParagraph(headerText, false, headerFormat);
     header.Alignment = Alignment.center;
 }
Пример #19
0
        public override void MergeField(DocX doc)
        {
            doc.AddCustomProperty(new Novacode.CustomProperty("CustomerBusinessName", this.CustomerSupplier.BusinessName));

            doc.AddCustomProperty(new Novacode.CustomProperty("EstimateNumber", this.EstimateNumber));
            doc.AddCustomProperty(new Novacode.CustomProperty("EstimateNumberSerie", this.EstimateNumberSerie));

            doc.AddCustomProperty(new Novacode.CustomProperty("DocumentName", this.DocumentName));
            doc.AddCustomProperty(new Novacode.CustomProperty("DocumentDate", (this.DateDocument ?? DateTime.Now).ToString("d")));
        }
        public DefaultDocumentSubSectionRenderer(DocX _document, IDocumentIdeaRenderer documentIdeaRenderer, IEnumerable<IDocumentIdeaFilter> filters)
        {
            _wordDocument = _document;

            _formatting = new FormattingRepository();

            _documentIdeaRenderer = documentIdeaRenderer;

            _filters = filters;
        }
Пример #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="doc"></param>
        public static void AddParagraph(List<List<string>> lines, DocX doc)
        {
            Paragraph p = doc.InsertParagraph();
            List<List<string>> l = lines;

            foreach (List<string> ss in l)
            {
                MatchCollection mc = Regex.Matches(ss[0], @"\{[0-9]+\}");
                string temp = ss[0];
                foreach (Match m in mc)
                {
                    foreach (Capture c in m.Captures)
                    {
                        temp = temp.Replace(c.Value, "¬");
                    }
                }

                string[] temps = temp.Split('¬');

                Append(p, temps[0]);

                for (int i = 1; i < ss.Count; i++)
                {
                    string pattern = @"\\(?<type>[a-zA-Z0-9]+)(?:\{(?<output>[^\{\}]+)\})?(?:\{(?<output2>[^\{\}]+)\})?";
                    Match m = Regex.Match(ss[i], pattern);
                    switch (m.Groups["type"].Value)
                    {
                        case "textbf":

                            Append(p, m.Groups["output"].Value);
                            p.Bold();

                            p.Append(temps[i]);
                            break;

                        case "emph":
                        case "textit":
                            Append(p, m.Groups["output"].Value);
                            p.Italic();
                            Append(p, temps[i]);
                            break;

                        case "rlap":
                            Append(p, m.Groups["output"].Value);
                            Append(p, m.Groups["output2"].Value);
                            break;

                        default:
                            throw new Exception(m.Groups["type"] + " is still under development");
                    }
                }

                string blah = doc.Xml.Value;
            }
        }
Пример #22
0
        public void CreateSampleDocument1()
        {
            //string fileName = @"C:\Users\tyho\Desktop\1.docx";
            string appPath  = Request.PhysicalApplicationPath;
            string fileDir  = @"Docs\";
            string fileDocx = "2.docx";
            string filePdf  = "2.pdf";

            string fileName     = appPath + fileDir + fileDocx;
            string fileName_new = appPath + fileDir + filePdf;

            //Novacode.Bookmark[] my = new Novacode.Bookmark[3];

            using (Novacode.DocX document = DocX.Load(fileName))
            {
                int i = 0;

                foreach (Novacode.Bookmark bookmark in document.Bookmarks)
                {
                    var bookmarks = document.Bookmarks[i].Name;

                    document.Bookmarks[bookmark.Name].SetText("(!!" + i.ToString() + "!!)");

                    i++;
                }
                //document.SaveAs(path2);
                document.Save();
            }

            //var wordApp = new Word.Application();
            //wordApp.Visible = true;
            //wordApp.Documents.Add();
            //wordApp.Selection.PasteSpecial(Link: true, DisplayAsIcon: true);

            //var wordApps = new Microsoft.Office.Interop.Word.Application();


            Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
            wordDocument = appWord.Documents.Open(fileName);
            wordDocument.ExportAsFixedFormat(fileName_new, Word.WdExportFormat.wdExportFormatPDF);


            //string fileName = @"C:\Users\tyho\Desktop\1.docx";
            //// Load the document.
            //using (DocX document = DocX.Load(fileName))
            //{
            //    // Replace text in this document.

            //    document.Bookmarks["Test"].SetText("HELLO2");
            //    //document.ReplaceText("%Test%", "HELLO");

            //    // Save changes made to this document.
            //    document.Save();
            //} // Release this document from memory.
        }
Пример #23
0
        private static Table CreateAndInsertInvoiceTableAfter(Table t, ref DocX document)
        {
            // Grab data from somewhere (Most likely a database)
            schooldbEntities DAO = new schooldbEntities();
            List<teacher> tlist = (from tt in DAO.teachers select tt).ToList<teacher>();

            /*
             * The trick to replacing one Table with another,
             * is to insert the new Table after the old one,
             * and then remove the old one.
             */
            Table invoice_table = t.InsertTableAfterSelf(tlist.Count + 1, 4);
            invoice_table.Design = TableDesign.LightShadingAccent1;

            #region Table title
            Formatting table_title = new Formatting();
            table_title.Bold = true;

            invoice_table.Rows[0].Cells[0].Paragraph.InsertText("Serial No.", false, table_title);
            invoice_table.Rows[0].Cells[0].Paragraph.Alignment = Alignment.center;
            invoice_table.Rows[0].Cells[1].Paragraph.InsertText("Employee Name", false, table_title);
            invoice_table.Rows[0].Cells[1].Paragraph.Alignment = Alignment.center;
            invoice_table.Rows[0].Cells[2].Paragraph.InsertText("Account No.", false, table_title);
            invoice_table.Rows[0].Cells[2].Paragraph.Alignment = Alignment.center;
            invoice_table.Rows[0].Cells[3].Paragraph.InsertText("Salary", false, table_title);
            invoice_table.Rows[0].Cells[3].Paragraph.Alignment = Alignment.center;
            #endregion

            // Loop through the rows in the Table and insert data from the data source.
            for (int row = 1; row < tlist.Count; row++)
            {

                    Paragraph cell_paragraph = invoice_table.Rows[row].Cells[0].Paragraph;
                    cell_paragraph.InsertText(row.ToString(), false);

                    cell_paragraph = invoice_table.Rows[row].Cells[1].Paragraph;
                    cell_paragraph.InsertText(tlist[row - 1].TeacherName.ToString(), false);

                    cell_paragraph = invoice_table.Rows[row].Cells[2].Paragraph;
                    cell_paragraph.InsertText(tlist[row - 1].Account_Number.ToString(), false);

                    cell_paragraph = invoice_table.Rows[row].Cells[3].Paragraph;
                    cell_paragraph.InsertText(tlist[row - 1].BasicSalary.ToString(), false);

            }

            // Let the tables coloumns expand to fit its contents.
            invoice_table.AutoFit = AutoFit.Contents;

            // Center the Table
            invoice_table.Alignment = Alignment.center;

            // Return the invloce table now that it has been created.
            return invoice_table;
        }
Пример #24
0
 private void Initialize()
 {
     if (NoTemplate)
     {
         this.document = DocX.Create(mappedHomePath + "NoTemplate.docx");
     }
     else
     {
         this.document = DocX.Load(mappedHomePath + fileName);
     }
 }
Пример #25
0
 public virtual void MergeField(DocX doc)
 {
     doc.AddCustomProperty(new Novacode.CustomProperty("DocumentTaskCenter.DocumentName", this.DocumentName));
     doc.AddCustomProperty(new Novacode.CustomProperty("DocumentTaskCenter.CodDocumentTaskCenter", this.CodDocumentTaskCenter));
     doc.AddCustomProperty(new Novacode.CustomProperty("DocumentTaskCenter.FieldA", this.FieldA));
     doc.AddCustomProperty(new Novacode.CustomProperty("DocumentTaskCenter.FieldB", this.FieldB));
     doc.AddCustomProperty(new Novacode.CustomProperty("DocumentTaskCenter.FieldC", this.FieldC));
 
 
 
 }
Пример #26
0
        private void RenderDocument(string outputFile, Document document)
        {
            _wordDocument = DocX.Create(outputFile);

            RenderParagraph(document.Text, _formatting.DocumentText);

            foreach (DocumentSection section in document.Sections)
            {
                RenderSection(section);
            }

            _wordDocument.Save();
        }
Пример #27
0
        public CompactPictureDir(Guid id, string parameters)
        {
            this.id = id;
            dd = DocX.Create("ttt.docx");

            pa = JsonConvert.DeserializeObject<Parameters>(parameters);

            dd.PageHeight = Pixels(pa.PageHeight);
            dd.PageWidth = Pixels(pa.PageWidth);
            dd.MarginLeft = Pixels(pa.MarginLeft);
            dd.MarginRight = Pixels(pa.MarginRight);
            dd.MarginTop = Pixels(pa.MarginTop);
            dd.MarginBottom = Pixels(pa.MarginBottom);
        }
Пример #28
0
 internal static void CreateRelsPackagePart(DocX Document, Uri uri)
 {
     PackagePart pp = Document.package.CreatePart(uri, "application/vnd.openxmlformats-package.relationships+xml", CompressionOption.Maximum);
     using (TextWriter tw = new StreamWriter(pp.GetStream()))
     {
         XDocument d = new XDocument
         (
             new XDeclaration("1.0", "UTF-8", "yes"),
             new XElement(XName.Get("Relationships", DocX.rel.NamespaceName))
         );
         var root = d.Root;
         d.Save(tw);
     }
 }
Пример #29
0
        private string CreateDoc( ) {
            var fileName = Seged.Seged.CreateFileName(versenyAdatok.VersenysorozatAzonosito, versenyAdatok.Azonosito, DokumentumTipus.Startlista.CsapatLista);
            document = DocX.Create( fileName );
            document.AddHeaders( );
            Seged.Seged.OldalSzamozas( document );
            AddHeader( );
            CsapatlistaHeaderTablazat( );
            CsapatokTablazat( );

            try { document.Save( ); } catch( System.Exception ) {
                MessageBox.Show( "A dokumentum meg van nyitva!", "Csapatlista", MessageBoxButton.OK, MessageBoxImage.Error );
            }
            return fileName;
        }
Пример #30
0
        protected override void BeginProcessing()
        {
            var resolvedPath = this.GetUnresolvedProviderPathFromPSPath(this.FilePath);

            if (!File.Exists(resolvedPath))
            {
                this.wordDocument = DocX.Create(resolvedPath);
            }
            else
            {
                this.wordDocument = DocX.Load(resolvedPath);
            }
            this.Contagem = 0;
        }
Пример #31
0
        private string CreateDoc( ) {
            var fileName = Seged.Seged.CreateFileName(versenyAdatok.VersenysorozatAzonosito, versenyAdatok.Azonosito, DokumentumTipus.Startlista.HianyzokLista);
            document = DocX.Create( fileName );
            Seged.Seged.OldalSzamozas( document );
            document.DifferentFirstPage = true;

            FirstPageFooter( );
            AddHeader( );
            HianyzoklistaHeaderTablazat( );
            HeaderTablazat( );
            HianyzokListaTablazat( );

            try { document.Save( ); } catch( System.Exception ) { MessageBox.Show( "A dokumentum meg van nyitva!", "Nevezési lista", MessageBoxButton.OK, MessageBoxImage.Error ); }
            return fileName;
        }
Пример #32
0
 /// <summary>
 /// Procedimiento para llenar la plantilla del tipo de contrato A.
 /// </summary>
 /// <param name="res">Registro de reservacion</param>
 /// <param name="data">Datos para rellenar el contrato.</param>
 /// <param name="doc">Instancia de documento word para rellenar.</param>
 public void fillContratoA(ref Novacode.DocX doc) //BANQUETES SERVICIO
 {
     doc.ReplaceText("<FECHA_ACTUAL>", this.fechaReservacion.ToString("dd/MMMM/yyyy"));
     doc.ReplaceText("<CLIENTE>", this.cliente.nombreCompleto);
     doc.ReplaceText("<FECHA>", this.fechaEventoInicial.ToString("dd/MMMM/yyyy"));
     doc.ReplaceText("<HORA_INICIAL>", this.fechaEventoInicial.ToString("HH:mm'hrs.'"));
     doc.ReplaceText("<TELEFONO>", this.cliente.telefono);
     doc.ReplaceText("<INVITADOS>", this.CantidadPersonas.ToString());
     doc.ReplaceText("<LUGAR>", this.lugar);
     doc.ReplaceText("<PLATILLO>", this.platillosInfo);
     doc.ReplaceText("<COSTO_TOTAL>", this.costo.ToString("C"));
     doc.ReplaceText("<ANTICIPO>", this.primerPago.cantidad.ToString("C"));
     doc.ReplaceText("<DETALLES>", this.Detalles == null?string.Empty:this.Detalles);
     doc.ReplaceText("<LISTA_DE_SERVICIOS>", this.enlistarServiciosParaContrato(null));
 }
Пример #33
0
 //替换指定段落的第一个图片
 /// <summary>
 /// 替换指定段落的第一个图片, 图片高度或宽度为0时使用图片的原始尺寸
 /// </summary>
 /// <param name="fromPath">文件路径</param>
 /// <param name="parIndex">有图片的段落的索引</param>
 /// <param name="imgPath">图片路径</param>
 /// <param name="alignment">对齐方式</param>
 /// <param name="height">图片高度</param>
 /// <param name="width">图片宽度</param>
 public void replacePicture(string fromPath, int parIndex, string imgPath, string alignment, double height, double width)
 {
     if (File.Exists(fromPath))
     {
         Novacode.DocX doc = Novacode.DocX.Load(fromPath);
         if (height == 0 || width == 0)
         {
             replacePicture(doc, parIndex, imgPath, alignment);
         }
         else
         {
             replacePicture(doc, parIndex, imgPath, alignment, height, width);
         }
         doc.Save();
     }
     return;
 }
Пример #34
0
 //插入图片(用户自定义图片尺寸), LEFT,RIGHT,CENTER
 /// <summary>
 /// 插入图片(用户自定义图片尺寸)
 /// </summary>
 /// <param name="docPath">文件路径</param>
 /// <param name="replaceFlag">替换标记</param>
 /// <param name="imgPath">图片路径</param>
 /// <param name="alignment">水平对齐方式,可以是:LEFT,RIGHT,CENTER</param>
 /// <param name="height">图片高度,为0时使用原始尺寸</param>
 /// <param name="width">图片宽度,为0时使用原始尺寸</param>
 public void InsertPicture(string docPath, string replaceFlag, string imgPath, string alignment, double height, double width)
 {
     if (File.Exists(docPath))
     {
         Novacode.DocX doc = Novacode.DocX.Load(docPath);
         if (height == 0 || width == 0)
         {
             InsertPicture(doc, replaceFlag, imgPath, alignment);
         }
         else
         {
             InsertPicture(doc, replaceFlag, imgPath, alignment, height, width);
         }
         doc.Save();
     }
     return;
 }
Пример #35
0
        /// <summary>
        /// Procedimiento para llenar la plantilla del tipo de contrato A.
        /// </summary>
        /// <param name="res">Registro de reservacion</param>
        /// <param name="data">Datos para rellenar el contrato.</param>
        /// <param name="doc">Instancia de documento word para rellenar.</param>
        public void fillContratoA(VMDataContractReservacion data, ref Novacode.DocX doc) //VENTURA KIDS
        {
            doc.ReplaceText("<FECHA>", data.fechaReservacion);
            doc.ReplaceText("<CLIENTE>", data.nombreCliente);
            doc.ReplaceText("<TELEFONO>", data.telefono);
            doc.ReplaceText("<INVITADOS>", data.cantidadPersonas);
            doc.ReplaceText("<DIA>", data.diaEvento);
            doc.ReplaceText("<MES>", data.mesEvento);
            doc.ReplaceText("<AÑO>", data.yearEvento);
            string strConcluye = string.Empty;

            if (this.fechaEventoInicial.Equals(this.fechaEventoFinal))
            {
                strConcluye = "mismo día";
            }
            else
            {
                strConcluye = this.fechaEventoFinal.Day +
                              " DE " + DatesTools.DatesToText.ConvertToMonth(this.fechaEventoFinal, "es")
                              .ToUpperInvariant() + " DEL " + this.fechaEventoFinal.Year;
            }

            doc.ReplaceText("<CONCLUYE>", strConcluye);
            doc.ReplaceText("<HORA_INICIO>", data.horaInicioEvento);
            doc.ReplaceText("<HORA_FIN>", data.horaFinEvento);

            /*doc.ReplaceText("<DURACION>", this.TiempoTotal.Minutes==0?this.TiempoTotal.ToString("hh")
             *  : this.TiempoTotal.ToString("hh 'con' mm 'minutos'"));*/

            doc.ReplaceText("<LAPSO>", this.sesionesString);
            doc.ReplaceText("<COSTO>", data.costo);
            doc.ReplaceText("<LETRA_TOTAL>", data.costoLetra);

            doc.ReplaceText("<ANTICIPO>", data.anticipo);
            doc.ReplaceText("<DEBE>", data.adeudo);
            doc.ReplaceText("<LETRA_DEUDA>", data.adeudoLetra);
        }
Пример #36
0
        public void CreateSampleDocument1()
        {
            //string fileName = @"C:\Users\tyho\Desktop\1.docx";
            string appPath  = Request.PhysicalApplicationPath;
            string fileDir  = @"Docs\";
            string fileDocx = "3.docx";
            string filePdf  = "3.pdf";

            string fileName     = appPath + fileDir + fileDocx;
            string fileName_new = appPath + fileDir + filePdf;

            //Novacode.Bookmark[] my = new Novacode.Bookmark[3];

            using (Novacode.DocX document = DocX.Load(fileName))
            {
                int i = 0;

                foreach (Novacode.Bookmark bookmark in document.Bookmarks)
                {
                    var bookmarks = document.Bookmarks[i].Name;

                    document.Bookmarks[bookmark.Name].SetText("(!!" + i.ToString() + "!!)");

                    i++;
                }
                //document.SaveAs(path2);
                document.Save();
            }

            //var wordApp = new Word.Application();
            //wordApp.Visible = true;
            //wordApp.Documents.Add();
            //wordApp.Selection.PasteSpecial(Link: true, DisplayAsIcon: true);

            //var wordApps = new Microsoft.Office.Interop.Word.Application();


            Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
            wordDocument = appWord.Documents.Open(fileName);
            wordDocument.ExportAsFixedFormat(fileName_new, Word.WdExportFormat.wdExportFormatPDF);
            wordDocument.Close();



            FileInfo fileInfo = new FileInfo(fileName_new);

            if (fileInfo.Exists)
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
                Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.Flush();
                Response.TransmitFile(fileInfo.FullName);
                Response.End();
            }



            string filename  = "myFile.txt";
            string disHeader = "Attachment; Filename=\"" + filename + "\"";

            Response.AppendHeader("Content-Disposition", disHeader);

            System.IO.FileInfo fileToDownload = new  System.IO.FileInfo("C:\\downloadJSP\\DownloadConv\\myFile.txt");
            Response.Flush();
            Response.WriteFile(fileToDownload.FullName);


            //string fileName = @"C:\Users\tyho\Desktop\1.docx";
            //// Load the document.
            //using (DocX document = DocX.Load(fileName))
            //{
            //    // Replace text in this document.

            //    document.Bookmarks["Test"].SetText("HELLO2");
            //    //document.ReplaceText("%Test%", "HELLO");

            //    // Save changes made to this document.
            //    document.Save();
            //} // Release this document from memory.
        }
Пример #37
0
 private void ExportWord()
 {
     if (Tables != null)
     {
         var columns = Columns;
         using (Docx.DocX doc = Docx.DocX.Create(FileName))
         {
             //表格的边框样式
             Docx.Border border = new Docx.Border();
             border.Tcbs = Docx.BorderStyle.Tcbs_single;
             int n = 0;
             foreach (TableEntity tableEntity in Tables)
             {
                 string tableId = tableEntity.ID.ToString();
                 //插入表名
                 Docx.Paragraph title = doc.InsertParagraph();
                 title.Append(tableEntity.TableName + "(" + tableEntity.Attr + ")");
                 title.Alignment = Docx.Alignment.center;
                 title.FontSize(15);
                 title.Bold();
                 title.SetLineSpacing(Docx.LineSpacingType.After, 1);
                 title.SetLineSpacing(Docx.LineSpacingType.Before, 1);
                 DataTable fields   = service.GetColumnDataTable(tableId);
                 int       rowCount = (fields == null ? 0 : fields.Rows.Count) + 1;
                 //计算表格多少行,多少列
                 Docx.Table table = doc.InsertTable(rowCount, columns.Count);
                 //先生成列头
                 Docx.Row colRow = table.Rows[0];
                 int      k      = 0;
                 foreach (string colKey in columns.Keys)
                 {
                     Docx.Cell colCell = colRow.Cells[k];
                     colCell.Paragraphs[0].Append(columns[colKey]).Alignment = Docx.Alignment.center;
                     colCell.SetBorder(Docx.TableCellBorderType.Top, border);
                     colCell.SetBorder(Docx.TableCellBorderType.Bottom, border);
                     colCell.SetBorder(Docx.TableCellBorderType.Left, border);
                     colCell.SetBorder(Docx.TableCellBorderType.Right, border);
                     k++;
                 }
                 for (int i = 0; i < fields.Rows.Count; i++)
                 {
                     //一个属性为一行
                     Docx.Row row = table.Rows[i + 1];
                     //循环每列
                     int j = 0;
                     foreach (string key in columns.Keys)
                     {
                         Docx.Cell cell = row.Cells[j];
                         string    text = fields.Rows[i][key].ToString();
                         if (key == requiredKey)
                         {
                             text = text.ToLower() == "true" ? "是" : "";
                         }
                         cell.Paragraphs[0].Append(text).Alignment = Docx.Alignment.center;
                         cell.Paragraphs[0].FontSize(10);
                         cell.SetBorder(Docx.TableCellBorderType.Top, border);
                         cell.SetBorder(Docx.TableCellBorderType.Bottom, border);
                         cell.SetBorder(Docx.TableCellBorderType.Left, border);
                         cell.SetBorder(Docx.TableCellBorderType.Right, border);
                         j++;
                     }
                 }
                 n++;
                 if (OnProgress != null)
                 {
                     OnProgress(this, new ProgressEventArgs()
                     {
                         Max = Tables.Count, Value = n
                     });
                 }
             }
             doc.Save();
         }
     }
 }