Save() public method

Save this document back to the location it was loaded from.
public Save ( ) : void
return void
示例#1
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;
        }
示例#2
0
文件: zDocX.cs 项目: labeuze/source
 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
        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.
        }
示例#4
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();
        }
示例#5
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;
        }
示例#6
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;
        }
示例#7
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;
 }
示例#8
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;
 }
        private string CreateDoc( ) {
            var fileName = Seged.Seged.CreateFileName( versenyAdatok.VersenysorozatAzonosito, versenyAdatok.Azonosito,
                DokumentumTipus.Eredmenylap.Verseny.Egyesulet );

            document = DocX.Create( fileName );
            document.AddHeaders( );
            Seged.Seged.OldalSzamozas( document );

            var header = document.Headers.odd;
            AddHeader( header );
            VersenyAdatokTablazat( header );
            AdatTablazat( );

            try { document.Save( ); } catch( Exception ) {
                MessageBox.Show( "A dokumentum meg van nyitva!", "Verseny Egyesület Eredménylap", MessageBoxButton.OK, MessageBoxImage.Error );
            }
            return fileName;
        }
    private static void InsertPicture(DocX doc, string filename, Formatting format)
    {
        using (MemoryStream memoryStream = new MemoryStream())
        {
            System.Drawing.Image myImg = System.Drawing.Image.FromFile(filename);

            myImg.Save(memoryStream, myImg.RawFormat);  // Save your picture in a memory stream.
            memoryStream.Seek(0, SeekOrigin.Begin);

            Novacode.Image img = doc.AddImage(memoryStream); // Create image.

            Paragraph p = doc.InsertParagraph("", false);

            Picture pic1 = img.CreatePicture();     // Create picture.

            p.InsertPicture(pic1, 0); // Insert picture into paragraph.

            doc.Save();
        }
    }
示例#11
0
        private string CreateDoc( ) {
              var fileName = Seged.Seged.CreateFileName( versenyAdatok.VersenysorozatAzonosito, versenyAdatok.Azonosito,
                    dokumentumTipus );

                document = DocX.Create( fileName );
                document.AddHeaders( );
                Seged.Seged.OldalSzamozas( document );

                var header = document.Headers.odd;
                AddHeader( header );
                VersenyAdatokTablazat( header );

                foreach( var ijtipus in ijtipusok._ijtipusok ) {
                    Table table ;
                    foreach( var korosztaly in ijtipus.korosztalyok.korosztalyok ) {
                        if( !korosztaly.eredmenyek.IsEmpty( ) ) {
                            var korosztalyParagraph = document.InsertParagraph();
                            korosztalyParagraph.Append( "Íjtípus: " );
                            korosztalyParagraph.Append( ijtipus.megnevezes ).Bold( );
                            korosztalyParagraph.AppendLine( "    Korosztály: " );
                            korosztalyParagraph.Append( korosztaly.megnevezes ).Bold( );

                            if( !korosztaly.eredmenyek.Nok.Count.Equals( 0 ) ) {
                                var nokParagraph = document.InsertParagraph();
                                nokParagraph.Append( "      Nők: " ).Bold( );

                                int helyezes = 0;
                                foreach( var eredmeny in korosztaly.eredmenyek.Nok ) {
                                    helyezes++;
                                    table = document.AddTable( 1, 7 );
                                    table.Rows[0].Cells[1].Paragraphs[0].Append( ( helyezes ) + "." );
                                    table.Rows[0].Cells[2].Paragraphs[0].Append( eredmeny.Sorszam.ToString( ) );
                                    table.Rows[0].Cells[3].Paragraphs[0].Append( eredmeny.Nev );
                                    table.Rows[0].Cells[4].Paragraphs[0].Append( eredmeny.Egyesulet );
                                    table.Rows[0].Cells[5].Paragraphs[0].Append( eredmeny.OsszPont.ToString( ) + " pont" );
                                    table.Rows[0].Cells[6].Paragraphs[0].Append( eredmeny.Szazalek.ToString( ) + "%" );
                                    TablazatFormazas( table );
                                    document.InsertTable( table );
                                }
                            }
                            if( !korosztaly.eredmenyek.Ferfiak.Count.Equals( 0 ) ) {
                                var nokParagraph = document.InsertParagraph();
                                nokParagraph.Append( "      Férfiak: " ).Bold( );

                                int helyezes = 0;
                                foreach( var eredmeny in korosztaly.eredmenyek.Ferfiak ) {
                                    helyezes++;
                                    table = document.AddTable( 1, 7 );
                                    table.Rows[0].Cells[1].Paragraphs[0].Append( ( helyezes ) + "." );
                                    table.Rows[0].Cells[2].Paragraphs[0].Append( eredmeny.Sorszam.ToString( ) );
                                    table.Rows[0].Cells[3].Paragraphs[0].Append( eredmeny.Nev );
                                    table.Rows[0].Cells[4].Paragraphs[0].Append( eredmeny.Egyesulet );
                                    table.Rows[0].Cells[5].Paragraphs[0].Append( eredmeny.OsszPont.ToString( ) + " pont" );
                                    table.Rows[0].Cells[6].Paragraphs[0].Append( eredmeny.Szazalek.ToString( ) + "%" );
                                    TablazatFormazas( table );
                                    document.InsertTable( table );
                                }
                            }
                            if( !korosztaly.eredmenyek.Egyben.Count.Equals( 0 ) ) {
                                var nokParagraph = document.InsertParagraph();
                                nokParagraph.Append( "      Egyben: " ).Bold( );

                                int helyezes = 0;
                                foreach( var eredmeny in korosztaly.eredmenyek.Egyben ) {
                                    helyezes++;
                                    table = document.AddTable( 1, 7 );
                                    table.Rows[0].Cells[1].Paragraphs[0].Append( ( helyezes ) + "." );
                                    table.Rows[0].Cells[2].Paragraphs[0].Append( eredmeny.Sorszam.ToString( ) );
                                    table.Rows[0].Cells[3].Paragraphs[0].Append( eredmeny.Nev );
                                    table.Rows[0].Cells[4].Paragraphs[0].Append( eredmeny.Egyesulet );
                                    table.Rows[0].Cells[5].Paragraphs[0].Append( eredmeny.OsszPont.ToString( ) + " pont" );
                                    table.Rows[0].Cells[6].Paragraphs[0].Append( eredmeny.Szazalek.ToString( ) + "%" );
                                    TablazatFormazas( table );
                                    document.InsertTable( table );
                                }
                            }
                        }
                    }
                }
                try { document.Save( ); } catch( Exception ) {
                    MessageBox.Show( "A dokumentum meg van nyitva!", "Verseny Teljes Eredménylap", MessageBoxButton.OK, MessageBoxImage.Error );
                }
                return fileName;
            }
示例#12
0
 public static void saveTable(ref DocX document)
 {
     document.Save();
 }
示例#13
0
        private void buttonCreateDoc_Click(object sender, EventArgs e)
        {
            if(saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.FileName != "")
            {
                filename = saveFileDialog.FileName;
                doc = DocX.Create(filename);

                buttonAdProb.Enabled = true;
                buttonAdProbRandom.Enabled = true;
                buttonOpenDoc.Enabled = true;

                Paragraph paragraph = doc.InsertParagraph("Test");
                paragraph.Alignment = Alignment.center;
                doc.InsertParagraph(Environment.NewLine);
                doc.Save();

                problemIndex = 0;

                MessageBox.Show("Document creat cu succes!");
            }
        }
示例#14
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.
        }
示例#15
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();
         }
     }
 }