本文整理汇总了C#中Microsoft.Office.Interop.Word.Document.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Save方法的具体用法?C# Document.Save怎么用?C# Document.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word.Document
的用法示例。
在下文中一共展示了Document.Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: insertarPrimerosCodigosDeBarra
//.........这里部分代码省略.........
{
isOpen = true;
}
finally
{
if (stream != null)
stream.Close();
}
if (isOpen)
{
Process[] proces = Process.GetProcessesByName("WINWORD");
foreach (Process proc in proces)
{
if (proc.MainWindowTitle == "")
proc.Kill();
}
MessageBox.Show("Existía un proceso abierto, y se ha cerrado correctamente. Favor de intentar nuevamente.", "Proceso Terminado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
//return -1;
}
doc = appWord.Documents.Open(path);
List<Word.Shape> lst = new List<Word.Shape>();
foreach (Word.Shape sh in doc.Shapes)
{
if (sh.Type.ToString() == "msoPicture")
{
while (sh.Name.Contains("\n"))
sh.Name = sh.Name.Replace("\n", "");
lst.Add(sh);
}
}
this.generarPrimerosCodigosDeBarra();
List<string> bcdUsados = new List<string>();
foreach (string bcd in lista_camposCodBarr)
{
foreach (Control txt in gb_CamposAdicionales.Controls.OfType<TextBox>())
{
if (!txt.Name.Contains(bcd.Replace("bcd", "")))
continue;
try
{
bcdUsados.Add(bcd);
float left, top, h, w;
string tempname = "";
List<Word.Range> ranges = new List<Word.Range>();
Word.Shape removed = null;
foreach (Word.Shape sh in lst)
{
if (sh.Name == bcd)
{
left = sh.Left;
top = sh.Top;
h = sh.Height;
w = sh.Width;
sh.ConvertToInlineShape();
foreach (Word.InlineShape s in doc.InlineShapes)
{
if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture)
{
tempname = sh.Name;
ranges.Add(s.Range);
s.Delete();
removed = sh;
}
}
foreach (Word.Range r in ranges)
{
r.InlineShapes.AddPicture(@rutasEnModAdmin.RutaDeTemp + "/" + bcd + ".jpg", Type.Missing, Type.Missing, Type.Missing);
}
Word.Shape pic;
foreach (Word.InlineShape s in doc.InlineShapes)
{
if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture)
{
pic = s.ConvertToShape();
pic.Name = tempname;
pic.Top = top;
pic.Left = left;
pic.Height = h;
pic.Width = w;
}
}
}
}
lst.Remove(removed);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
doc.Save();
doc.Saved = true;
((Microsoft.Office.Interop.Word._Document)doc).Close();
foreach (string str in bcdUsados)
lista_camposCodBarr.Remove(str);
}
示例2: insertarPrimerosCodigosDeBarra
private void insertarPrimerosCodigosDeBarra(bool EtiquetaMultiples)
{
this.generarPrimerosCodigosDeBarra(true);
List<string> bcdUsados = new List<string>();
foreach (Etiqueta_C.Estructura_etqMultiple etqM in ListaEtiquetasMultiples)
{
string path = @rutasEnModAdmin.RutaDePlantillas + "/temp_EtiquetaActual" + ListaEtiquetasMultiples.IndexOf(etqM) + ".docx";
appWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
appWord.Visible = false;
doc = appWord.Documents.Open(path);
List<Word.Shape> lst = new List<Word.Shape>();
foreach (Word.Shape sh in doc.Shapes)
{
if (sh.Type.ToString() == "msoPicture")
{
while (sh.Name.Contains("\n"))
sh.Name = sh.Name.Replace("\n", "");
lst.Add(sh);
}
}
foreach (string bcd in lista_camposCodBarr)
{
foreach (Control txt in gb_CamposAdicionales.Controls.OfType<TextBox>())
{
if (!txt.Name.Contains(bcd.Replace("bcd", "")))
continue;
try
{
bcdUsados.Add(bcd);
float left, top, h, w;
string tempname = "";
List<Word.Range> ranges = new List<Word.Range>();
Word.Shape removed = null;
foreach (Word.Shape sh in lst)
{
if (sh.Name == bcd)
{
left = sh.Left;
top = sh.Top;
h = sh.Height;
w = sh.Width;
sh.ConvertToInlineShape();
foreach (Word.InlineShape s in doc.InlineShapes)
{
if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture)
{
tempname = sh.Name;
ranges.Add(s.Range);
s.Delete();
removed = sh;
}
}
foreach (Word.Range r in ranges)
{
if (File.Exists(@rutasEnModAdmin.RutaDeTemp + "/" + bcd + ".jpg"))
r.InlineShapes.AddPicture(@rutasEnModAdmin.RutaDeTemp + "/" + bcd + ".jpg", Type.Missing, Type.Missing, Type.Missing);
}
ranges.Clear();
Word.Shape pic;
foreach (Word.InlineShape s in doc.InlineShapes)
{
if (s.Type == Word.WdInlineShapeType.wdInlineShapePicture)
{
pic = s.ConvertToShape();
pic.Name = tempname;
pic.Top = top;
pic.Left = left;
pic.Height = h;
pic.Width = w;
}
}
}
}
lst.Remove(removed);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.ToString());
}
}
}
doc.Save();
doc.Saved = true;
((Microsoft.Office.Interop.Word._Document)doc).Close();
}
foreach (string str in bcdUsados)
lista_camposCodBarr.Remove(str);
}
示例3: buttonPDF_Click
private void buttonPDF_Click(object sender, RoutedEventArgs e)
{
var wrd_name = Convert.ToString(comboBox.SelectedValue);
var xls_name = textBoxExcelPath.Text;
if (string.IsNullOrEmpty(wrd_name))
{
MessageBox.Show("Выберите шаблон КП");
return;
}
ProgressWnd pw = new ProgressWnd("Создаем КП по шаблону...");
pw.Show();
string fn = "";
try
{
WordApp = new Wd.Application() { Visible = false };
WordDoc = WordApp.Documents.Open(wrd_name);
fn=SaveW(WordApp, WordDoc);
var ad = DataContext as AllData;
ReplaceAll(WordDoc,"[OurCompany]", ad.Our.OurCompany);
ReplaceAll(WordDoc, "[ForWho]", ad.ForWho);
ReplaceAll(WordDoc, "[ContractPeriodYears]", ad.HowLongYears);
ReplaceAll(WordDoc, "[ServiceType]", ad.ServiceType);
ReplaceAll(WordDoc, "[DaysToStart]", ad.DaysToStart);
ReplaceAll(WordDoc, "[DateStart]", ad.DateStart);
ReplaceAll(WordDoc, "[CostMonthString]", ad.CostMonthString);
ReplaceAll(WordDoc, "[CostMonth]", ad.CostMonth);
ReplaceAll(WordDoc, "[CostYear]", (o2d(ad.CostMonth) * 12).ToString());
ReplaceAll(WordDoc, "[Address]", ad.Address);
ReplaceAll(WordDoc, "[Date]", ad.Date);
ReplaceAll(WordDoc, "[Area]", ad.Area.ToString());
ReplaceAll(WordDoc, "[NameObject]", ad.ForWho);
int kk = 1;
foreach(var ee in ad.e1)
{
var trg="[Extra" + kk + "]";
if (ee.IsSelected==true)
{
ReplaceAll(WordDoc, trg, ee.Text);
}
else
{
WordDoc.Bookmarks["bExtra" + kk].Range.Delete();
ReplaceAll(WordDoc, trg, "");
}
++kk;
}
kk = 1;
foreach (var ee in ad.e2)
{
var trg = "[Sod" + kk + "]";
if (ee.IsSelected == true)
{
ReplaceAll(WordDoc, trg, ee.Text);
}
else
{
WordDoc.Bookmarks["bSod" + kk].Range.Delete();
ReplaceAll(WordDoc, trg, "");
}
++kk;
}
if(radioButton.IsChecked==true)
{
ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn1);
}
else
{
ReplaceAll(WordDoc, "[NaOsnovanii]", ad.NaOsn2);
}
if(checkBoxServicePlan.IsChecked==false)
{
Wd.Range delRange = WordDoc.Range();
delRange.Start=WordDoc.Bookmarks["b0"].Range.Start;
delRange.End = WordDoc.Bookmarks["b1"].Range.End;
delRange.Delete();
}
ReplaceAll(WordDoc, "[ServicePlanStart]", "");
ReplaceAll(WordDoc, "[ServicePlanEnd]", "");
//ReplaceAll(WordDoc, "[NameCost]", ad.ForWho);
//Sebestoimost
Wd.Table tt=FindTable(WordDoc, WordDoc.Bookmarks["tab6"]);
double total = 0;
foreach (var s in ad.Sebestimost)
{
tt.Rows.Add();
tt.Cell(tt.Rows.Count, 1).Range.Text = s.Name;
//.........这里部分代码省略.........
示例4: 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();
//.........这里部分代码省略.........
示例5: processWord
public void processWord(string saved_path, bool newSmry)
{
word_app = createWordApp();
this.insertBookmark(saved_doc_list);
object strFileName = saved_path;
Object Nothing = System.Reflection.Missing.Value;
object readOnly = false;
object isVisible = false;
word_wrt = word_app.Documents.Open(ref strFileName, ref Nothing, ref readOnly,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref isVisible, ref Nothing,
ref Nothing, ref Nothing, ref Nothing);
word_wrt.Activate();
//word_wrt.Paragraphs.Last.Range.Text = "test text" + "\n";//加个结束符(增加一段),否则再次插入的时候就成了替换.
this.writeSammary();
//保存
word_wrt.Save();
// 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;
}