本文整理汇总了C#中Microsoft.Office.Interop.Word.Document.Activate方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Activate方法的具体用法?C# Document.Activate怎么用?C# Document.Activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word.Document
的用法示例。
在下文中一共展示了Document.Activate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyBodyToMeeting
private void CopyBodyToMeeting(AppointmentItem ai, ref MeetingItem meetingItem)
{
ThisAddIn.g_log.Info("Copy AppointmentItem body to MeetingItem enter");
Word.Document Doc = new Word.Document();
Word.Document Doc2 = new Word.Document();
Word.Application App1;
Word.Selection Sel;
Doc = ai.GetInspector.WordEditor as Word.Document;
if (Doc != null)
{
ThisAddIn.g_log.Info(string.Format("appointmentItem doc length is {0}.", Doc.Content.Text.Length));
Doc.Activate();
Doc.Select();
App1 = Doc.Windows.Application;
Sel = App1.Selection;
Sel.WholeStory();
Sel.Copy();
Doc2 = meetingItem.GetInspector.WordEditor as Word.Document;
if (Doc2 != null)
{
Doc2.Activate();
object start = 0;
Range newRang = Doc2.Range(ref start, ref start);
int ioo = Doc2.Sections.Count;
Section sec = Doc2.Sections[1];
sec.Range.InsertBreak(Type.Missing);//插入换行符
sec.Range.PasteAndFormat(WdRecoveryType.wdPasteDefault);
meetingItem.Save();
ThisAddIn.g_log.Info(string.Format("meetingItem doc length is {0}.", Doc2.Content.Text.Length));
//ThisAddIn.g_log.Info(string.Format("mailItem body length is {0}.", meetingItem.Body.Length));
if (meetingItem.Body == null || meetingItem.Body.Length < 100)
{
Doc2.Activate();
((_Inspector)(meetingItem.GetInspector)).Activate();
}
}
}
Doc = null;
Doc2 = null;
App1 = null;
Sel = null;
ThisAddIn.g_log.Info("Copy AppointmentItem body to MeetingItem exit");
}
示例2: ExportWord
/// <summary>
/// 调用模板生成word
/// </summary>
/// <param name="templateFile">模板文件</param>
/// <param name="fileName">生成的具有模板样式的新文件</param>
public void ExportWord(string templateFile, string fileName)
{
try
{
#region 生成word应用程序对象
//生成word程序对象
object obj = System.Reflection.Missing.Value;
Word.Application app = new Word.Application();
//模板文件
string TemplateFile = templateFile;
//生成的具有模板样式的新文件
string FileName = fileName;
//模板文件拷贝到新文件
File.Copy(TemplateFile, FileName);
//生成documnet对象
//Word.Document doc=app.Documents.Add(ref obj,ref obj,ref obj,ref,obj,ref obj);
Word.Document doc = new Word.Document();
object Obj_FileName = FileName;
object Visible = false;
object ReadOnly = false;
object missing = System.Reflection.Missing.Value;
//打开文件
doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
doc.Activate();
#endregion
//声明书签数组
object[] BookMark = new object[100];
//赋值书签名
BookMark[0] = "lb0001";
BookMark[1] = "lb0002";
BookMark[2] = "lb0003";
BookMark[3] = "lb0004";
BookMark[4] = "lb0005";
BookMark[5] = "lb0006";
BookMark[6] = "lb0007";
BookMark[7] = "lb0008";
BookMark[8] = "tb001";
BookMark[9] = "tb002";
BookMark[10] = "tb003";
BookMark[11] = "tb004";
BookMark[12] = "tb005";
BookMark[13] = "tb006";
BookMark[14] = "tb007";
BookMark[15] = "tb008";
BookMark[16] = "tb009";
BookMark[17] = "tb010";
BookMark[18] = "tb011";
BookMark[19] = "tb012";
BookMark[20] = "tb013";
BookMark[21] = "tb014";
BookMark[22] = "tb015";
BookMark[23] = "tb016";
BookMark[24] = "tb017";
BookMark[25] = "tb018";
//赋值任意数据到书签的位置
string str = "大同333";
doc.Bookmarks.get_Item(ref BookMark[0]).Range.Text = "7788";
doc.Bookmarks.get_Item(ref BookMark[1]).Range.Text = str;
doc.Bookmarks.get_Item(ref BookMark[2]).Range.Text = "50";
doc.Bookmarks.get_Item(ref BookMark[3]).Range.Text = "2号";
doc.Bookmarks.get_Item(ref BookMark[4]).Range.Text = "6";
doc.Bookmarks.get_Item(ref BookMark[5]).Range.Text = "200";
//添加图片
doc.Bookmarks.get_Item(ref BookMark[7]).Select();
app.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
app.Selection.InlineShapes.AddPicture(@"E:\dzy\picture\12.png", ref missing, ref missing, ref missing);
////判断指定的图片是否存在
//if (File.Exists(@"..\..\sources\images\12.png"))
//{
// File.Delete(@"..\..\sources\images\12.png");
//}
#region 表格操作
//文档中创建表格
Range range = doc.Bookmarks.get_Item(ref BookMark[25]).Range;//表格插入位置
Word.Table newTable = doc.Tables.Add(range, 12, 3, ref missing, ref missing);
//设置表格样式
newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleThickThinLargeGap;
newTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
newTable.Columns[1].Width = 100f;
//.........这里部分代码省略.........
示例3: CopyBody
private void CopyBody(AppointmentItem ai, MailItem mailItem)
{
ThisAddIn.g_log.Info("Copy AppointmentItem body to MailItem enter");
Word.Document Doc = new Word.Document();
Word.Document Doc2 = new Word.Document();
Word.Application App1;
Word.Selection Sel;
Doc = ai.GetInspector.WordEditor as Word.Document;
Word.Application App2;
Word.Selection Sel2;
if (Doc != null)
{
ThisAddIn.g_log.Info(string.Format("appointmentItem doc length is {0}.", Doc.Content.Text.Length));
Doc.Activate();
Doc.Select();
App1 = Doc.Windows.Application;
Sel = App1.Selection;
Sel.WholeStory();
Sel.Copy();
Doc2 = mailItem.GetInspector.WordEditor as Word.Document;
if (Doc2 != null)
{
Doc2.Activate();
Doc2.Select();
App2 = Doc2.Windows.Application;
Sel2 = App2.Selection;
Sel2.WholeStory();
try
{
Sel2.PasteAndFormat(WdRecoveryType.wdPasteDefault);
}
catch (System.Exception ex)
{
ThisAddIn.g_log.Error(string.Format("copy to body exception, {0}", ex.ToString()));
}
mailItem.Save();
ThisAddIn.g_log.Info(string.Format("mailItem doc length is {0}.", Doc2.Content.Text.Length));
if (mailItem.Body == null || mailItem.Body.Length < 100)
{
Doc2.Activate();
((_Inspector)(mailItem.GetInspector)).Activate();
}
}
}
Doc = null;
Doc2 = null;
App1 = null;
App2 = null;
Sel = null;
Sel2 = null;
ThisAddIn.g_log.Info("Copy AppointmentItem body to MailItem exit");
}
示例4: zkylExportWord
/// <summary>
/// 调用模板生成word
/// </summary>
/// <param name="templateFile">模板文件</param>
/// <param name="fileName">生成的具有模板样式的新文件</param>
public void zkylExportWord(string templateFile, string newfileName)
{
#region 生成word应用程序对象
object obj = System.Reflection.Missing.Value;
Word.Application app = new Word.Application();
//模板文件
string TemplateFile = templateFile;
//生成的具有模板样式的新文件
string newFileName = newfileName;
//模板文件拷贝到新文件
File.Copy(TemplateFile, newFileName);
//生成documnet对象
//Word.Document doc=app.Documents.Add(ref obj,ref obj,ref obj,ref,obj,ref obj);
Word.Document doc = new Word.Document();
object Obj_FileName = newFileName;
object Visible = false;
object ReadOnly = false;
object missing = System.Reflection.Missing.Value;
//打开文件
doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
#endregion
try
{
doc.Activate();
//声明书签数组
object[] BookMarkzkyl = new object[70];
#region 钻孔应力标签定位
//赋值书签名
BookMarkzkyl[0] = "zkyllbtitle";
BookMarkzkyl[1] = "zkyltimestart";
BookMarkzkyl[2] = "zkyltimeend";
BookMarkzkyl[3] = "zkyltabledate";
BookMarkzkyl[4] = "zkyltableman";
BookMarkzkyl[5] = "zkylsensor01";
BookMarkzkyl[6] = "zkylsensor02";
BookMarkzkyl[7] = "zkylsensor03";
BookMarkzkyl[8] = "zkylsensor04";
BookMarkzkyl[9] = "zkylsensor05";
BookMarkzkyl[10] = "zkylsensor06";
BookMarkzkyl[11] = "zkylsensor07";
BookMarkzkyl[12] = "zkylsensor08";
BookMarkzkyl[13] = "zkylsensor09";
BookMarkzkyl[14] = "zkylmintime01";
BookMarkzkyl[15] = "zkylmintime02";
BookMarkzkyl[16] = "zkylmintime03";
BookMarkzkyl[17] = "zkylmintime04";
BookMarkzkyl[18] = "zkylmintime05";
BookMarkzkyl[19] = "zkylmintime06";
BookMarkzkyl[20] = "zkylmintime07";
BookMarkzkyl[21] = "zkylmintime08";
BookMarkzkyl[22] = "zkylmintime09";
BookMarkzkyl[23] = "zkylmaxtime01";
BookMarkzkyl[24] = "zkylmaxtime02";
BookMarkzkyl[25] = "zkylmaxtime03";
BookMarkzkyl[26] = "zkylmaxtime04";
BookMarkzkyl[27] = "zkylmaxtime05";
BookMarkzkyl[28] = "zkylmaxtime06";
BookMarkzkyl[29] = "zkylmaxtime07";
BookMarkzkyl[30] = "zkylmaxtime08";
BookMarkzkyl[31] = "zkylmaxtime09";
BookMarkzkyl[32] = "zkylaverage01";
BookMarkzkyl[33] = "zkylaverage02";
BookMarkzkyl[34] = "zkylaverage03";
BookMarkzkyl[35] = "zkylaverage04";
BookMarkzkyl[36] = "zkylaverage05";
BookMarkzkyl[37] = "zkylaverage06";
BookMarkzkyl[38] = "zkylaverage07";
BookMarkzkyl[39] = "zkylaverage08";
BookMarkzkyl[40] = "zkylaverage09";
BookMarkzkyl[41] = "zkylminvalue01";
BookMarkzkyl[42] = "zkylminvalue02";
BookMarkzkyl[43] = "zkylminvalue03";
BookMarkzkyl[44] = "zkylminvalue04";
BookMarkzkyl[45] = "zkylminvalue05";
BookMarkzkyl[46] = "zkylminvalue06";
BookMarkzkyl[47] = "zkylminvalue07";
BookMarkzkyl[48] = "zkylminvalue08";
BookMarkzkyl[49] = "zkylminvalue09";
BookMarkzkyl[50] = "zkylmaxvalue01";
BookMarkzkyl[51] = "zkylmaxvalue02";
BookMarkzkyl[52] = "zkylmaxvalue03";
//.........这里部分代码省略.........
示例5: createTCWidthDocument
public void createTCWidthDocument()
{
List<List<string>> joistDataByMark = arrangedJoistDataByMark();
Word.Application wordApp = new Word.Application();
wordApp.Visible = false;
Word.Document wordDoc = new Word.Document();
wordDoc.Activate();
wordDoc.Paragraphs.SpaceAfter = 0;
///
Word.Selection selection = wordApp.Application.Selection;
selection.Font.Name = "Calibri";
selection.Font.Size = 11;
selection.Font.Bold = 1;
Word.Section section = selection.Sections.Add();
Word.Range headerRange = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
string jobNumber = joistDataByMark[0][6];
string[] jobNumberArray = jobNumber.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
jobNumber = jobNumberArray[0] + "-" + jobNumberArray[1];
headerRange.Text = "TOP CHORD WIDTHS: "+ joistDataByMark[0][5] + " [NMBS: " + jobNumber + "]" + " " + joistDataByMark[0][7] +
"\r\n\r\n" + " MARK QUANTITY DESCRIPTION BASE LENGTH TC WIDTH";
Word.Range footerRange = section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
footerRange.Fields.Add(footerRange, Word.WdFieldType.wdFieldPage);
footerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
selection.HomeKey(Word.WdUnits.wdStory, 0);
//selection.Text = "TOP CHORD WIDTHS: \r\n";
// selection.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
// selection.MoveDown(Word.WdUnits.wdLine, 1);
selection.Font.Bold = 0;
Word.Table tableTCWidths = wordApp.ActiveDocument.Tables.Add(selection.Range,joistDataByMark.Count()+1,5);
tableTCWidths.Cell(1, 1).Range.Text = "";
tableTCWidths.Cell(1, 2).Range.Text = "";
tableTCWidths.Cell(1, 3).Range.Text = "";
tableTCWidths.Cell(1, 4).Range.Text = "";
tableTCWidths.Cell(1, 5).Range.Text = "";
for (int i = 1; i <= 5; i++)
{
tableTCWidths.Cell(1, i).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
//tableTCWidths.Cell(1, i).Range.Underline = Word.WdUnderline.wdUnderlineSingle;
tableTCWidths.Cell(1, i).Range.Font.Bold = 1;
// tableNailBackSheetTitle.Cell(i,1).Borders[Word.WdBorderType.wdBorderBottom].LineStyle = Word.WdLineStyle.wdLineStyleSingle;
}
int rowcounter = 0;
int numRows = joistDataByMark.Count()+1;
for (int row = 2; row <= numRows; row++)
{
for (int col = 1; col<=5; col++)
{
tableTCWidths.Cell(row, col).Range.Text = joistDataByMark[row - 2][col - 1];
}
}
for (int i = 1; i <= 4; i++)
{
tableTCWidths.Cell(i, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
}
tableTCWidths.Columns[1].Width = 50;
tableTCWidths.Columns[2].Width = 60;
tableTCWidths.Columns[3].Width = 95;
tableTCWidths.Columns[4].Width = 80;
tableTCWidths.Columns[5].Width = 60;
for (int row =1; row<=joistDataByMark.Count()+1; row++)
{
tableTCWidths.Rows[row].Height = 7;
}
for (int row = 1; row <= joistDataByMark.Count() + 1; row++)
{
for (int col = 1; col <= 5; col++)
{
tableTCWidths.Cell(row, col).Range.Borders[Word.WdBorderType.wdBorderBottom].LineStyle = Word.WdLineStyle.wdLineStyleSingle;
tableTCWidths.Cell(row, col).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
}
}
wordApp.Visible = true;
}
示例6: WordOpen
private void WordOpen(string strFileName)
{
object fileName = strFileName;
object readOnly = false;
object isVisible = true;
_WordDoc = _WordApplication.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
_WordDoc.Activate();
}
示例7: zzylExportWord
public void zzylExportWord(string templateFile, string newfileName)
{
#region 生成word应用程序对象
object obj = System.Reflection.Missing.Value;
Word.Application app = new Word.Application();
//模板文件
string TemplateFile = templateFile;
//生成的具有模板样式的新文件
string newFileName = newfileName;
//模板文件拷贝到新文件
File.Copy(TemplateFile, newFileName);
//生成documnet对象
//Word.Document doc=app.Documents.Add(ref obj,ref obj,ref obj,ref,obj,ref obj);
Word.Document doc = new Word.Document();
object Obj_FileName = newFileName;
object Visible = false;
object ReadOnly = false;
object missing = System.Reflection.Missing.Value;
//打开文件
doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref Visible,
ref missing, ref missing, ref missing,
ref missing);
#endregion
try
{
//生成word程序对象
doc.Activate();
//-----------数据煤矿名称读取操作----------
string strsqltitle = "select 煤矿名称 from 煤矿基本信息表 ";
DataTable dt = db.Query(strsqltitle);
DataRow dr = dt.Rows[0];
string inform = dr["煤矿名称"].ToString();
//----------------------------------------------------------
//获取当前系统时间不显示秒
DateTime currentTime = System.DateTime.Now;
string strnowtime = currentTime.ToString("f");
//获取当前用户
string currentuser = login.REAL_NAME;
#region zzyl导出报表
//---------------------取zzyl时间段-------------------
string date_begin_hourzzyl = (comboBox5.Text == "") ? "0" : comboBox5.Text;
string date_begin_minzzyl = (comboBox7.Text == "") ? "0" : comboBox7.Text;
string date_over_hourzzyl = (comboBox6.Text == "") ? "23" : comboBox6.Text;
string date_over_minzzyl = (comboBox8.Text == "") ? "59" : comboBox8.Text;
string date_beginzzyl = dateTimePicker1.Text.ToString();
date_beginzzyl += " " + date_begin_hourzzyl + ":" + date_begin_minzzyl;
date_beginzzyl += ":00";
string date_overzzyl = dateTimePicker2.Text.ToString();
date_overzzyl += " " + date_over_hourzzyl + ":" + date_over_minzzyl;
date_overzzyl += ":00";
DateTime d_beginzzyl = DateTime.Parse(date_beginzzyl);
DateTime d_overzzyl = DateTime.Parse(date_overzzyl);
//----赋值zzyl数据到公共书签的位置---------------------
doc.Bookmarks.get_Item(ref BookMark_zz[0]).Range.Text = inform;
doc.Bookmarks.get_Item(ref BookMark_zz[1]).Range.Text = date_beginzzyl;
doc.Bookmarks.get_Item(ref BookMark_zz[2]).Range.Text = date_overzzyl;
doc.Bookmarks.get_Item(ref BookMark_zz[3]).Range.Text = strnowtime;
doc.Bookmarks.get_Item(ref BookMark_zz[4]).Range.Text = currentuser;
//-------------------------------------------------------------
//---------------取支柱压力传感器编号与所选传感器列表相对应----------
string cgqbh = "";
int row_num = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
cgqbh = dataGridView1.Rows[i].Cells["传感器编号"].Value.ToString();
//------------------------判断时间段内有数据做导出---------------------------------
//-----------------------------------------------------------------------------------
if ((bool)dataGridView1.Rows[i].Cells[1].FormattedValue) //前柱
{
fillword(cgqbh, "前柱", ref doc, row_num, d_beginzzyl, d_overzzyl);
row_num++;
}
if ((bool)dataGridView1.Rows[i].Cells[2].FormattedValue) //后柱
{
fillword(cgqbh, "后柱", ref doc, row_num, d_beginzzyl, d_overzzyl);
row_num++;
//.........这里部分代码省略.........
示例8: CreateWordsDocumentToOne
public static bool CreateWordsDocumentToOne(object docPath, string savaAs, string docName,DataRowView[] candidats,string presedinte,string membru1, string membru2)
{
int candiLength = candidats.Length;
Console.WriteLine("LENGTH" + candiLength);
object missing = Missing.Value;
// Word.Document[] adocs = new Word.Document[candidats.Length];
string output = savaAs + docName + "-" + "candidats.docx";
Application createEmptyDocApp = null;
Word.Document createEmptyDoc = null;
Word._Application wordAppForOutput = null;
Word._Document wordDocument = null;
Word.Document aDoc = null;
Word.Application wordApp = null;
try
{
if (File.Exists(output))
File.Delete(output);
if (!File.Exists(output))
{
createEmptyDocApp = new Application();
createEmptyDoc = createEmptyDocApp.Documents.Add();
createEmptyDocApp.ActiveDocument.SaveAs(output, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
createEmptyDoc.Close();
if (createEmptyDocApp != null)
{
createEmptyDocApp.Quit();
Marshal.FinalReleaseComObject(createEmptyDocApp);
}
createEmptyDoc = null;
createEmptyDocApp = null;
}
else
{
return false;
}
object pageBreak = Word.WdBreakType.wdPageBreak;
wordAppForOutput = new Word.Application();
wordAppForOutput.Visible = false;
wordDocument = wordAppForOutput.Documents.Open(
output
, false, false, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, true,
ref missing, ref missing, ref missing, ref missing);
wordDocument.Activate();
for (int i = 0; i < candiLength; ++i)
{
aDoc = new Word.Document();
wordApp = new Word.Application();
DataRow candidat = candidats[i].Row;
List<int> processesbeforegen = getRunningProcesses();
// string savePath =(string) savaAs + docName + " " + candidat["Nume"] + "_" + candidat["Prenume"] ;
string savePath = savaAs + "tempDoc";
if (File.Exists((string)docPath))
{
Console.WriteLine("Fajlnal vagyok");
object readOnly = false; //default
object isVisible = false;
wordApp.Visible = false;
aDoc = wordApp.Documents.Open(ref docPath, ref missing, ref readOnly,
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);
aDoc.Activate();
Console.WriteLine("megnyitva");
//Find and replace:
FindAndReplace(wordApp, "{NrMatricol}", candidat["NrMatricol"]);
FindAndReplace(wordApp, "{Nume}", candidat["Nume"]);
FindAndReplace(wordApp, "{Prenume}", candidat["Prenume"]);
FindAndReplace(wordApp, "{Tata}", candidat["Tata"]);
FindAndReplace(wordApp, "{Mama}", candidat["Mama"]);
FindAndReplace(wordApp, "{CNP>", candidat["CNP"]);
FindAndReplace(wordApp, "{DataNasterii}", candidat["DataNasterii"]);
FindAndReplace(wordApp, "{LoculNasterii}", candidat["LoculNasterii"]);
//.........这里部分代码省略.........
示例9: CreateWordsDocuments
public static bool CreateWordsDocuments(object docPath, string savaAs, string docName, DataRowView[] candidats, string presedinte, string membru1, string membru2)
{
int candiLength = candidats.Length;
Console.WriteLine("LENGTH" + candiLength);
object missing = Missing.Value;
// Word.Document[] adocs = new Word.Document[candidats.Length];
Word.Document aDoc = null;
Word.Application wordApp = null;
try{
for (int i = 0; i < candiLength; ++i)
{
aDoc = new Word.Document();
wordApp = new Word.Application();
DataRow candidat = candidats[i].Row;
List<int> processesbeforegen = getRunningProcesses();
string savePath =(string) savaAs + docName + " " + candidat["Nume"] + "_" + candidat["Prenume"] ;
if (File.Exists((string)docPath))
{
Console.WriteLine("Fajlnal vagyok");
object readOnly = false; //default
object isVisible = false;
wordApp.Visible = false;
aDoc = wordApp.Documents.Open(ref docPath, ref missing, ref readOnly,
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);
aDoc.Activate();
Console.WriteLine("megnyitva");
//Find and replace:
FindAndReplace(wordApp, "{NrMatricol}", candidat["NrMatricol"]);
FindAndReplace(wordApp, "{Nume}", candidat["Nume"]);
FindAndReplace(wordApp, "{Prenume}", candidat["Prenume"]);
FindAndReplace(wordApp, "{Tata}", candidat["Tata"]);
FindAndReplace(wordApp, "{Mama}", candidat["Mama"]);
FindAndReplace(wordApp, "{CNP>", candidat["CNP"]);
FindAndReplace(wordApp, "{DataNasterii}", candidat["DataNasterii"]);
FindAndReplace(wordApp, "{LoculNasterii}", candidat["LoculNasterii"]);
FindAndReplace(wordApp, "{Strada}", candidat["Strada"]);
FindAndReplace(wordApp, "{Nr}", candidat["Nr"]);
FindAndReplace(wordApp, "{Bloc}", candidat["Bloc"]);
FindAndReplace(wordApp, "{Scara}", candidat["Scara"]);
FindAndReplace(wordApp, "{Ap}", candidat["Ap"]);
FindAndReplace(wordApp, "{Localitate}", candidat["Localitate"]);
FindAndReplace(wordApp, "{Judet}", candidat["Judet"]);
FindAndReplace(wordApp, "{Cp}", candidat["Cp"]);
FindAndReplace(wordApp, "{Telefon}", candidat["Telefon"]);
FindAndReplace(wordApp, "{Studii}", candidat["Studii"]);
FindAndReplace(wordApp, "{Profesia}", candidat["Profesia"]);
FindAndReplace(wordApp, "{LocMunca}", candidat["LocMunca"]);
FindAndReplace(wordApp, "{Presedinte}", presedinte);
FindAndReplace(wordApp, "{Membru1}", membru1);
FindAndReplace(wordApp, "{Membru2}", membru2);
Console.WriteLine("cserelgetes");
object saveFullPath = savePath;
aDoc.SaveAs2(ref saveFullPath, 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);
//Close Document:
aDoc.Close(ref missing, ref missing, ref missing);
wordApp.Quit(false);
Marshal.FinalReleaseComObject(wordApp);
aDoc = null;
wordApp = null;
List<int> processesaftergen = getRunningProcesses();
Console.WriteLine("COUNT > " + processesbeforegen.Count + " " + processesaftergen.Count);
killProcesses(processesbeforegen, processesaftergen);
}
else
{
System.Windows.MessageBox.Show("file dose not exist.");
return false;
}
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show("Error occured at Report!\n"+ex.Message);
return false;
//.........这里部分代码省略.........
示例10: Open
public void Open(string strFileName)
{
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
{
if (p.ProcessName.ToLower().Equals("winword"))
p.Kill();
}
object fileName = strFileName;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
oWordApplic = new Word.ApplicationClass();
oDoc = oWordApplic.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
oDoc.Activate();
}
示例11: openWord
public void openWord()
{
this.wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
this.wordApp.Visible = false;
object missing = System.Reflection.Missing.Value;
this.wordDoc = wordApp.Documents.Open(this.outputPath,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);
wordDoc.Activate();
}
示例12: _Search
private void _Search(List<string> pathToFile, string stringToSearch, string pathToSave = null)
{
logger.Info("Clean the return List of coincidences");
FileInfo.Clear();
logger.Info("initializing paramenter objects");
object oMissing = System.Reflection.Missing.Value;
object oTrue = true;
object oFalse = false;
try
{
logger.Info("instantiating word app");
word = new Word.Application();
logger.Info("instantiating document of word app");
doc = new Word.Document();
logger.Info("reading each files on path ={0}", pathToFile);
foreach (string item in pathToFile)
{
object fileName = item;
logger.Info("opening the file");
doc = word.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
logger.Info("file opened and activates");
FileInfo fiIn = new FileInfo();
fiIn.FileName = item;
fiIn.FileNameOut = string.Format(@"{0}\{1}.pdf", pathToSave, Guid.NewGuid().ToString());
logger.Info("searching the text on each paragraphs");
foreach (Word.Paragraph Paragraph in doc.Paragraphs)
{
Word.Range rng = Paragraph.Range;
rng.Find.Text = stringToSearch.Trim();
rng.Find.ClearFormatting();
rng.Find.Forward = true;
rng.Find.Replacement.ClearFormatting();
rng.Find.Wrap = Word.WdFindWrap.wdFindStop;
rng.Find.Execute(
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
while (rng.Find.Found)
{
rng.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdDarkYellow;
rng.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdWhite;
MatchesInfo maIn = new MatchesInfo();
maIn.Page = (int)rng.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdActiveEndAdjustedPageNumber);
maIn.Line = (int)rng.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdFirstCharacterLineNumber);
fiIn.MatchesList.Add(maIn);
logger.Info("text matching and highlight");
rng.Find.Execute(
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
}
FileInfo.Add(fiIn);
if (!string.IsNullOrEmpty(pathToSave))
{
logger.Info("exporting the file");
doc.ExportAsFixedFormat(
fiIn.FileNameOut,
Word.WdExportFormat.wdExportFormatPDF,
OptimizeFor: Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen,
BitmapMissingFonts: true, DocStructureTags: false);
logger.Info("file exported");
}
object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
object originalFormat = Word.WdOriginalFormat.wdOriginalDocumentFormat;
object routeDocument = false;
((Word._Document)doc).Close(ref saveOption, ref originalFormat, ref routeDocument);
}
}
catch (Exception ex)
{
//TODO: Manipular errores;
logger.Info("An exception has detected");
logger.Error(ex);
throw new Exception("");
throw;
}
finally
{
((Word._Application)word).Quit(ref oFalse, ref oMissing, ref oMissing);
}
}
示例13: CreateAndActive
/// <summary>
/// 新建并打开一个文档(默认缺省值)
/// </summary>
public void CreateAndActive()
{
_wordDocument = CreateOneDocument(missing, missing, missing, missing);
_wordDocument.Activate();
}
示例14: 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();
//.........这里部分代码省略.........
示例15: OpenAndActive
/// <summary>
/// 打开指定文件
/// </summary>
/// <param name="FileName">文件名(包含路径)</param>
/// <param name="IsReadOnly">打开后是否只读</param>
/// <param name="IsVisibleWin">打开后是否可视</param>
/// <returns>打开是否成功</returns>
public bool OpenAndActive(string FileName, bool IsReadOnly, bool IsVisibleWin)
{
if (string.IsNullOrEmpty(FileName))
{
return false;
}
try
{
_wordDocument = OpenOneDocument(FileName, missing, IsReadOnly, missing, missing, missing, missing, missing, missing, missing, missing, IsVisibleWin, missing, missing, missing, missing);
_wordDocument.Activate();
return true;
}
catch
{
return false;
}
}