当前位置: 首页>>代码示例>>C#>>正文


C# Document.SaveAs方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Word.Document.SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C# Document.SaveAs方法的具体用法?C# Document.SaveAs怎么用?C# Document.SaveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Word.Document的用法示例。


在下文中一共展示了Document.SaveAs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveFileAs

        public override void SaveFileAs(string fileName, FileType type)
        {
            object Visible = false;
            object start1 = 0;
            object end1 = 0;

            WordApp = new Word.Application();
            doc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
            Range rng = doc.Range(ref start1, ref missing);
            rng.InsertAfter(parsedFile.contentRaw);
            object filename = fileName;

            doc.SaveAs(ref filename, ref missing, ref missing,
                                ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing,
                                ref missing, ref missing, ref missing, ref missing);

            WordApp.Visible = true;
            //doc.RemoveDocumentInformation(WdRemoveDocInfoType.wdRDIAll);
            //doc.DocumentInspectors;
        }
开发者ID:sashaMilka,项目名称:MultiReader,代码行数:22,代码来源:DocParser.cs

示例2: RunSummary

        void RunSummary()
        {
            NotamFilter filter = new NotamFilter();
            
            filter.TypeFilter = NType;
            filter.FromDateFilter = FromDate;
            filter.ToDateFilter = ToDate;
            _notamService.Archive();
            List<Notam> notamList = _notamService.GetFilterNotams(filter);
            List<string> aeroList = notamList.Select(x => x.FirAero).ToList<string>();
            Dictionary<string, string> aeroDic = _aerodomService.GetAddressList(aeroList);
            object fileName = System.Configuration.ConfigurationManager.AppSettings.Get("DocTemplatePath").ToString();
            Word.Application word = new Word.Application();
            Word.Document doc = new Word.Document();
            object missing = System.Type.Missing;
            try
            {
                doc = word.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                doc.Activate();
                string newFileName = fileName.ToString();
                newFileName = newFileName.Replace(".docx", "1.docx");
                doc.SaveAs(newFileName);
                Process.Start(newFileName.ToString());
                int icol = 2, irow = 1;
                var queryYear = notamList.GroupBy(item => item.Year).Select(group =>
                                        new
                                        {
                                            Year = group.Key,
                                            nums = group.OrderBy(x => x.Number)
                                        }).OrderBy(group => group.nums.First().Number);
                Word.Table newTable = doc.Application.ActiveDocument.Tables[1];
                //                newTable.Rows.Add(newTable.Rows[1]);
                foreach (var yearItem in queryYear)
                {
                    newTable.Cell(irow, 1).Range.Text = "20" + yearItem.Year + ":";
                    foreach (var nt in yearItem.nums)
                    {
                        if (icol > 14)
                        {
                            icol = 2;
                            irow++;
                            newTable.Rows.Add(ref missing);

                        }
                        if (nt.Number!=null)
                            newTable.Cell(irow, icol).Range.Text = nt.Number.ToString();
                        doc.Save();
                        icol++;
                    }
                    irow++;
                    icol = 2;
                    newTable.Rows.Add(ref missing);
                    doc.Save();
                }
                

                //add0519
                var queryAero = notamList.Where(x => x.FirAero!=null).GroupBy(item => item.FirAero).Select(group =>
                        new
                        {
                            Aero = group.Key,
                            Addr = aeroDic.ContainsKey(group.Key) ? aeroDic[group.Key]:"",
                            nums = group.OrderBy(x => x.Number)
                        }).OrderBy(group => group.Addr);
                Word.Table secTable = doc.Application.ActiveDocument.Tables[2];
                irow = 1;
                //                newTable.Rows.Add(newTable.Rows[1]);
                
                foreach (var aeroItem in queryAero)
                {
                    secTable.Rows.Add(ref missing);
                    irow++;
                    secTable.Cell(irow, 3).Range.Font.Size = 11;
                    secTable.Cell(irow, 3).Range.Font.Bold = 1;
                    secTable.Cell(irow, 3).Range.Font.Italic = 1;
                    string strAeroCity = aeroItem.Addr;
                    secTable.Cell(irow, 3).Range.Text = strAeroCity + "." + aeroItem.Aero;
                    doc.Save();

                    foreach (var nt in aeroItem.nums)
                    {
                        secTable.Rows.Add(ref missing);
                        irow++;
                        secTable.Cell(irow, 1).Range.Font.Bold = 0;
                        secTable.Cell(irow, 1).Range.Font.Italic = 0;
                        secTable.Cell(irow, 1).Range.Font.Size = 10;
                        if (nt.Number!=null)
                            secTable.Cell(irow, 1).Range.Text = nt.Type+ nt.Number.ToString();
                        secTable.Cell(irow, 2).Range.Font.Bold = 0;
                        secTable.Cell(irow, 2).Range.Font.Italic = 0;
                        secTable.Cell(irow, 2).Range.Font.Size = 10;
                        if (nt.FromDate!=null)
                            secTable.Cell(irow, 2).Range.Text = nt.FromDate.Substring(0, 6);
                        string str = nt.FromDate + "/" + nt.ToDate + "/" + nt.PermEst + "\n";
                        string iteme = nt.EFreeText;
                        secTable.Cell(irow, 3).Range.Font.Bold = 0;
                        secTable.Cell(irow, 3).Range.Font.Italic = 0;
                        secTable.Cell(irow, 3).Range.Font.Size = 9;
                        secTable.Cell(irow, 3).Range.Text = str + iteme;
                        doc.Save();
//.........这里部分代码省略.........
开发者ID:ali60,项目名称:NOTAM,代码行数:101,代码来源:NotamSummaryViewModel.cs

示例3: Button1_Click

 protected void Button1_Click(object sender, EventArgs e)
 {
     object Nothing = System.Reflection.Missing.Value;//定义一个missing
     wordApp = new Msword.ApplicationClass();//对wordapp进行初始化
     wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);//对一个wordDoc进行初始化
     object filename = "F:\\aa.doc";
     if (File.Exists(filename.ToString()))//判断文件是否存在
     {
         File.Delete(filename.ToString());//若文件存在就删除这个文件
     }
     wordApp.Visible = false;//设置动态建立的word文档可见
     wordApp.Selection.PageSetup.LeftMargin = wordApp.CentimetersToPoints(float.Parse("2"));//设置word文档的左边距
     wordApp.Selection.PageSetup.RightMargin = wordApp.CentimetersToPoints(float.Parse("2"));//设置word文档右边距
     wordApp.ActiveWindow.HorizontalPercentScrolled = 11;//设置文档的水平滑动距离
     wordApp.ActiveWindow.View.Type = Msword.WdViewType.wdOutlineView;//设置文档的页眉类型
     wordApp.ActiveWindow.View.SeekView = Msword.WdSeekView.wdSeekCurrentPageHeader;//设置文档的页眉是显示在文档的头部
     wordApp.ActiveWindow.ActivePane.Selection.InsertAfter("这是我的页眉内容");
     wordApp.Selection.ParagraphFormat.Alignment = Msword.WdParagraphAlignment.wdAlignParagraphRight;//设置页眉内容的对齐方式
     //wordApp.ActiveWindow.View.SeekView = Msword.WdSeekView.wdSeekMainDocument;//跳出页眉设置
     wordApp.Selection.ParagraphFormat.LineSpacing = 11f;//设置段落的距离为11f
     Msword.Paragraph para1;//定义一个段落为para1
     para1 = wordDoc.Paragraphs.Add(ref Nothing);//对para1进行初始化
     para1.Range.Text = "这是我的内容2这是我的内容2这是我的内容2这是我的内容2这是我的内容2这是我的内容2这是我的内容2这是我的内容2这是我的内容2";//对段落para1进行添加内容
     para1.Format.CharacterUnitFirstLineIndent = 2;//设置首行缩进
     para1.Range.Font.Color = Msword.WdColor.wdColorBlue;//设置字体的颜色
     para1.Format.SpaceAfter = 6;//在段落para1后面设置空行为6
     para1.Range.InsertParagraphAfter();//将段落para1添加到文档中
     Msword.Paragraph para2;//同上
     object endofdoc = "\\endofdoc";//定义标签endofdoc,"endofdoc"表示文档的末尾书签
     object range1 = wordDoc.Bookmarks.get_Item(ref endofdoc).Range;//定位到文档的书签处
     para2 = wordDoc.Paragraphs.Add(ref range1);//同上
     para2.Range.Text = "asfdasdfasdfasdffasdfsadfasdfasfdasdfas";//同上
     para2.Range.InsertParagraphAfter();//同上
     Msword.Paragraph para3;//同上
     object range2 = wordDoc.Bookmarks.get_Item(ref endofdoc).Range;//同上
     para3 = wordDoc.Paragraphs.Add(ref range2);//同上
     para3.Range.Text = "eeeeeeeeeeeeeeeeeeeeeeee";//同上
     object sttar = (object)(para3.Range.Start + 2);//"para3.Range.Start "表示para3段落的开始处加上两个字符
     object eend = (object)(para3.Range.Start + 2);//同上
     wordDoc.Range(ref sttar, ref eend).InsertBefore("ttt");//定位到para3段落的开始处加上两个字符并添加内容"ttt"
     para3.Format.CharacterUnitFirstLineIndent = 2;//设置首行缩进
     para3.Range.Font.Bold = 5;//设置段落para3字体颜色
     para3.Range.InsertParagraphAfter();//同上
     Msword.Table table1 = wordDoc.Tables.Add(para3.Range, 8, 8, ref Nothing, ref Nothing);//在文档中添加8行8列的表格
     table1.Cell(1, 1).Range.Font.Color = Msword.WdColor.wdColorBrown;//设置表格中的第1行1列的字体颜色为wdColorBrown
     table1.Cell(1, 1).Range.Text = "搜点的撒旦";//在表格中的第一行第一类中添加内容
     table1.Range.ParagraphFormat.Alignment = Msword.WdParagraphAlignment.wdAlignParagraphRight;//设置表格中的内容alignment
     table1.Cell(3, 3).Merge(table1.Cell(8, 3));//将3行3列一直到8行3列进行组合成一列
     object row = 4;
     object col = 4;
     table1.Cell(3, 1).Split(ref row, ref col);//将3行1列分开为4行4列
     string picturefile = "D:\\ly\\应用\\test.jpg";//设置图片的路径
     object linktofile = false;
     object linktodoctument = true;
     object x1 = (object)(para2.Range.Start);
     object x2 = (object)(para2.Range.End);
     object rr1 = wordDoc.Range(ref x1, ref x2);
     wordDoc.Application.ActiveDocument.InlineShapes.AddPicture(picturefile, ref linktofile, ref linktodoctument, ref rr1);//将图片添加到文档中
     //将图片的外形设置为可变
     Msword.Shape shape1 = wordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
     shape1.WrapFormat.Type = Msword.WdWrapType.wdWrapSquare;
     //保存wordDoc
     wordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
         ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
         ref Nothing, ref Nothing);
     //释放内存
     wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
     wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
 }
开发者ID:Angliy,项目名称:DemoForTest,代码行数:69,代码来源:Default9.aspx.cs

示例4: startMarkup


//.........这里部分代码省略.........
                    citas = new List<MarkupStruct>();
                    /*Creamos una instancia del formulario*/
                    this.formValidate = ValidateMarkup.Instance;
                    this.formValidate.CitationStyle = this.citationStyle;
                    this.formValidate.DtdVersion = this.dtdVersion;
                    this.formValidate.DtdType = this.dtdType;
                    this.formValidate.updateDTDInfo();
                    /* Buscando parrafo por parrafo */
                    foreach (Word.Paragraph parrafo in docSeleccion.Paragraphs){
                        fixedMarkedString = null;
                        marked = false;
                        parsed = false;
                        /* Mandamos el texto de cada parrafo a una funcion que nos lo regresara marcado y quitamos el salto linea */
                        object parrafoStart = parrafo.Range.Start;
                        object parrafoEnd = (parrafo.Range.End - 1);
                        originalString = ActiveDocument.Range(ref parrafoStart, ref parrafoEnd).Text;
                        //MessageBox.Show(subjetcString, "Texto de parrafo");
                        if (originalString != null)
                        {
                            /*Verificamos si la cadena original ya esta marcada*/
                            if (originalString.IndexOf("[") == 0 && originalString.LastIndexOf("]") == originalString.Length - 1)
                            {
                                marked = true;
                                parsed = true;
                                fixedMarkedString = originalString;
                                clearTag = fixedMarkedString.Substring(1, fixedMarkedString.IndexOf("]") - 1);
                                /*Nos aseguramos de que la etiqueta no contenga algun atributo buscando un espacio*/
                                if(clearTag.IndexOf(" ") > 0){
                                    clearTag = clearTag.Substring(0, clearTag.IndexOf(" "));
                                }
                                /*Con la ayuda de la instancia del formulario limpiamos la cadena marcada*/
                                this.tags.getChilds(clearTag);
                                originalString = this.formValidate.clearTag(fixedMarkedString, clearTag);
                            }
                            citas.Add(new MarkupStruct(originalString, fixedMarkedString, ActiveDocument.Range(ref parrafoStart, ref parrafoEnd), marked, parsed));
                        }
                    }
                    /* Mandamos llamar al formulario para la validación de las citas*/
                    this.formValidate.startValidate(ref citas);

                    if (this.formValidate.ShowDialog() == DialogResult.OK)
                    {
                        /* Ocultamos la aplicacion durante los procesos de reemplazo y coloreado para hacer mas rapida la aplicacion */
                        Globals.ThisAddIn.Application.Visible = false;
                        waitForm = Waiting.Instance;
                        waitForm.Show();
                        /* Reemplzando texto original por el marcado */
                        /* Utilizando el rango de texto de la cita original y reemplzado el texto por el marcado */
                        int citaIndex = 0;
                        foreach (MarkupStruct cita in citas)
                        {
                            if (cita.Marked && cita.Colorized)
                            {
                                Clipboard.Clear();
                                cita.MarkedRtb.SelectAll();
                                Clipboard.SetText(cita.MarkedRtb.SelectedRtf, TextDataFormat.Rtf);
                                cita.RngCita.Paste();
                                cita.RngCita.Font.Size = 11;
                                Clipboard.Clear();
                            }
                            if (this.dtdType == "doc") {
                                if (citaIndex == 0)
                                    cita.RngCita.InsertBefore("[refs]");
                                if (citaIndex == (citas.Count - 1))
                                    cita.RngCita.InsertAfter("[/refs]");
                            }
                            citaIndex++;
                        }
                        /* Mostramos de nuevo la aplicacion */
                        waitForm.Hide();
                        Globals.ThisAddIn.Application.Visible = true;
                        /*Guardamos los cambios*/
                        if (!ActiveDocument.ReadOnly)
                        {
                            object FileName = Path.Combine(ActiveDocument.Path, ActiveDocument.Name);
                            object FileFormat = Word.WdSaveFormat.wdFormatFilteredHTML;
                            if (!ActiveDocument.Path.Contains(".htm"))
                                FileFormat = missing;
                            try
                            {
                                ActiveDocument.SaveAs(ref FileName, ref FileFormat, ref missing,
                                        ref missing, ref missing, ref missing,
                                        ref missing, ref missing,
                                        ref missing, ref missing,
                                        ref missing, ref missing, ref missing,
                                        ref missing, ref missing, ref missing);
                            }catch (Exception e)
                            {
                                if (log.IsErrorEnabled) log.Error(e.Message);
                            }
                        }
                        else
                        {
                            MessageBox.Show(Resources.RegexMarkup_messageOnlyRead);
                        }
                    }
                }
            }
            if (log.IsInfoEnabled) log.Info("End");
        }
开发者ID:swarzesherz,项目名称:RegexMarkup,代码行数:101,代码来源:RegexMarkup.cs

示例5: createWord

        public void createWord(string saved_path, bool newSmry)
        {
            word_app = createWordApp();
            this.insertBookmark(saved_doc_list);
            object strFileName = saved_path;
            //MessageBox.Show(strFileName.ToString());
            if (System.IO.File.Exists((string)strFileName))
                System.IO.File.Delete((string)strFileName);
            Object Nothing = System.Reflection.Missing.Value;

            word_wrt = word_app.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

            object oStyleName = Word.WdBuiltinStyle.wdStyleBodyText;  //"Heading 1";
            word_wrt.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            word_wrt.Paragraphs.Last.Range.set_Style(ref oStyleName);
            string strContent = "Schlüsselwörter \r";
            word_wrt.Paragraphs.Last.Range.Font.Size = 14;
            word_wrt.Paragraphs.Last.Range.Font.Bold = 1;
            word_wrt.Paragraphs.Last.Range.Text = strContent;

            this.writeSammary();

            //将WordDoc文档对象的内容保存为DOC文档
            word_wrt.SaveAs(ref strFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            //关闭WordDoc文档对象
            word_wrt.Close(ref Nothing, ref Nothing, ref Nothing);

            //Test code ##
            this.buildTOC(saved_path, newSmry);
            //Test code ##

            try
            {
                word_show.Quit(ref Nothing, ref Nothing, ref Nothing);
                word_app.Quit(ref Nothing, ref Nothing, ref Nothing);
            }
            catch(Exception)
            {
            }

            word_app = null;
            word_show = null;
        }
开发者ID:Narts,项目名称:wordOpenXML,代码行数:43,代码来源:Utilities.cs


注:本文中的Microsoft.Office.Interop.Word.Document.SaveAs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。