本文整理汇总了C#中System.Windows.Forms.Document.Activate方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Activate方法的具体用法?C# Document.Activate怎么用?C# Document.Activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Document
的用法示例。
在下文中一共展示了Document.Activate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getTableByName
public Table getTableByName(Document doc, string title, Microsoft.Office.Interop.Word.Application testWord) //testWord下的doc文档下
//找到标题为title的表格
{
doc.Activate();
testWord.Selection.HomeKey(WdUnits.wdStory, Type.Missing);
Find find = testWord.Selection.Find;
find.Text = title;
Selection currentSelect = testWord.Selection;
bool ifFind = false;
while (find.Execute())
{
string s = currentSelect.Paragraphs[1].Range.Text.Trim();
if (s.Equals(title))
{
ifFind = true;
break;
}
}
if (ifFind == false)
{
return null;
}
while (currentSelect.Tables.Count == 0)
{
currentSelect.GoToNext(WdGoToItem.wdGoToLine);
}
Table table = currentSelect.Tables[1];
return table;
}
示例2: generateTOC
private void generateTOC(Document doc, ApplicationClass app)
{
doc.Activate();
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Object oUpperHeadingLevel = "1";
Object oLowerHeadingLevel = "3";
Object oTOCTableID = "TableOfContents";
app.Selection.Start = 0;
app.Selection.End = 0;//将光标移动到文档开始位置
object beginLevel = 2;//目录开始深度
object endLevel = 2;//目录结束深度
object rightAlignPageNumber = true;// 指定页码右对其
doc.TablesOfContents.Add(app.Selection.Range, ref oTrue, ref oUpperHeadingLevel,
ref oLowerHeadingLevel, ref oMissing, ref oTOCTableID, ref oTrue,
ref oTrue, ref oMissing, ref oTrue, ref oTrue, ref oTrue);
}
示例3: getTable
private Table getTable(Document doc)//移动文档光标到表格并获取表格
{
doc.Activate();//使doc文档为活动文档
Selection currentSelect = testWord.Selection;
while (currentSelect.Tables.Count == 0)
{
currentSelect.GoToNext(WdGoToItem.wdGoToLine);
}
Table table = currentSelect.Tables[1];
return table;
}
示例4: getFind
private Find getFind(Document doc, string s)
{
doc.Activate();
testWord.Selection.Find.Text = s;
return testWord.Selection.Find;
}
示例5: getTableOfContents
private string[] getTableOfContents(Document doc)
{
doc.Activate();
generateTOC(doc, testWord);//自动生成目录
Range tocRange = doc.TablesOfContents[1].Range;
string[] tableOfContents = delimiterTOC(tocRange.Text);
return tableOfContents;
}
示例6: highLightKeyWords
public void highLightKeyWords(string keyWord,
Application testWord, Document doc, RichTextBox richTextBox, Label keyWordCountLabel, RichTextBox statisticsInfor)/*对当前testWord的Doc文档在richTextBox进行
* keyWord的高亮显示,并在listBox上显示
* 关键字个数和在staticticsInfor上输出数值信息*/
{
doc.Activate();
string s = abstarctRichBoxString(keyWord, testWord);
richTextBox.Clear();
if (s == "")
{
richTextBox.Text = "此关键字不存在";
}
else
{
richTextBox.Text = s;
}
int sumLength = 0;//记录标识的绝对位置
int length = keyWord.Length;
int k = s.IndexOf(keyWord);
int count = 0;
int start = 0;
while (k >= 0)
{
count++;
start = sumLength + k;
richTextBox.Select(start, length);
richTextBox.SelectionBackColor = SysColor.ERROR;
s = s.Remove(0, k + length);//缩短总的testPage
sumLength += k + length;
k = s.IndexOf(keyWord);
getStatisticsInformation(count, k, s);
}
string t = "数目:" + count;
if (keyWordCountLabel != null)
{
keyWordCountLabel.Text = t; ;//关键字统计的listBox赋值关键字个数
}
//System.Diagnostics.Debug.WriteLine(tests);
if (statisticsInfor != null)
{
if (tests == "")
{
statisticsInfor.Text = "未找到该关键字的数值信息";
}
else
{
statisticsInfor.Text = tests;
}
}
//清空前一次统计信息
tests = "";
list.Clear();
}
示例7: OpenpdfFileByBrowser
private void OpenpdfFileByBrowser()
{
try
{
//save file to folder
if (Page.IsPostBack)
{
string fileName = Session["uploadedfile"].ToString();
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
////convert file from doc to pfd
Document doc = new Document(fileName);
doc.Activate();
// doc.SaveAs("d:/desktop/document.pdf", WdSaveFormat.wdFormatPDF); tempcomment
//temp code
string[] filePaths = Directory.GetFiles(Server.MapPath("~/PDFdoc/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
GridView1.DataSource = files;
GridView1.DataBind();
//temp code
}
}
catch (Exception ex)
{
lblCatchError.Text = ex.Message.ToString();
}
}
示例8: highLightRichString
public void highLightRichString(RichTextBox rbTableTest, Application testWord, Document doc,List<string>keyItemList)
{
doc.Activate();
testWord.Selection.HomeKey(WdUnits.wdStory, Type.Missing);
string richString = generateRichString(testWord,keyItemList);
int[] countNumber = new int[keyItemList.Count];
getCountNumber(testWord,countNumber,keyItemList);
rbTableTest.Clear();
if (richString == "")
{
rbTableTest.Text = "此文档不存在这些关键字信息";
return;
}
else
{
rbTableTest.Text = richString;
}
int i = 0;
int sumLength = 0;//记录标识的绝对位置
foreach (string keyWord in keyItemList)
{
int length = keyWord.Length;
int k = richString.IndexOf(keyWord);
int count = 0;
int start = 0;
while (k >= 0)
{
count++;
start = sumLength + k;
rbTableTest.Select(start, length);
rbTableTest.SelectionBackColor = SysColor.ERROR;
richString = richString.Remove(0, k + length);//缩短总的testPage
sumLength += k + length;
k = richString.IndexOf(keyWord);
if (count == countNumber[i])
{
break;
}
}
i++;
}
}
示例9: FileSelectorClick
private void FileSelectorClick(object sender, EventArgs e)
{
OpenFileDialog im = new OpenFileDialog();
if (im.ShowDialog() == DialogResult.OK)
{
wordDocPath = im.FileName;
Console.WriteLine("File Selected is " + wordDocPath);
//open word file here
ap = new Microsoft.Office.Interop.Word.Application();
ap.Application.Visible = true;
try
{
doc = ap.Documents.Open( @wordDocPath, ReadOnly: false, Visible: true );
doc.Activate();
ap.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
MessageBox.Show("Start taking screenshots by clicking on Capture button.");
this.Controls.Remove(fileSelector);
fileSelector.Dispose();
capture = new Button();
capture.Name = "captureButton";
capture.Text = "Capture";
capture.Size = new Size(this.Width - 200, this.Height - 60);
capture.Location = new System.Drawing.Point(
(this.Width - capture.Width) / 8,
(this.Height - capture.Height) / 6);
capture.Click += new System.EventHandler(this.CaptureClick);
this.Controls.Add(capture);
}catch ( Exception ex )
{
MessageBox.Show("Unable to open word document. Refer Console for proper error message.");
Console.WriteLine( "Exception Caught: " + ex.Message ); // Could be that the document is already open (/) or Word is in Memory(?)
// Ambiguity between method 'Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit'. Using method group.
// ap.Quit( SaveChanges: false, OriginalFormat: false, RouteDocument: false );
try{
( (_Application)ap ).Quit( SaveChanges: false, OriginalFormat: false, RouteDocument: false );
System.Runtime.InteropServices.Marshal.ReleaseComObject( ap );
}catch (Exception exception){
Console.WriteLine(exception.ToString());
}
}
}else{
MessageBox.Show("Please select any word document to save screenshots");
}
}
示例10: btnGenerateNewPWs_Click
private void btnGenerateNewPWs_Click(object sender, EventArgs e)
{
//killprocess("winword");
app = new Microsoft.Office.Interop.Word.Application { Visible = false };
System.Data.DataTable dt = new System.Data.DataTable();
string qry = "SELECT * FROM ibis_pw_userlist WHERE ibis_pw_userlist_active = 1 AND ibis_pw_userlist_id > 1";
//string qry = "SELECT * FROM ibis_pw_userlist WHERE ibis_pw_userlist_active = 1";
Random randnum = new Random();
int _min4 = 0;
int _max4 = 9999;
int _min6 = 0;
int _max6 = 999999;
using (MySqlConnection dbh = new MySqlConnection(Properties.Resources.DB_CONNSTR_HES))
{
dbh.Open();
using (MySqlDataAdapter da = new MySqlDataAdapter(qry, dbh))
{
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
doc = app.Documents.Add(@"C:\Users\dc1_000\Documents\HoldenEngineering\pw_memo_template.docx");
doc.Activate();
string newpw;
if (row["ibis_pw_userlist_un"].ToString().Equals("dholden"))
{
newpw = String.Format("{0:000000}", randnum.Next(_min6, _max6));
}
else
{
// HERE IS WHERE ONE COULD RANDOMIZE THE PLACEMENT OF
// THE ABBREVIATION RELATIVE TO THE FOUR-DIGIT NUMBER
newpw = row["ibis_pw_userlist_abbr"].ToString() + String.Format("{0:0000}", randnum.Next(_min4, _max4));
}
doc.Bookmarks["bmNameLbl"].Range.Text = row["ibis_pw_userlist_label"].ToString();
doc.Bookmarks["bmGenPW"].Range.Text = newpw;
doc.Bookmarks["bmUserName"].Range.Text = row["ibis_pw_userlist_un"].ToString();
doc.Bookmarks["bmOldPW"].Range.Text = row["ibis_pw_userlist_currpw"].ToString();
doc.Bookmarks["bmNewPW"].Range.Text = newpw;
doc.Bookmarks["bmNewPW2"].Range.Text = newpw;
doc.PrintOut();
((Microsoft.Office.Interop.Word._Document)doc).Close(false, ref missing, ref missing);
try
{
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = dbh;
cmd.CommandText = "UPDATE ibis_pw_userlist SET ibis_pw_userlist_currpw = @npw, ibis_pw_userlist_prevpw = @opw WHERE ibis_pw_userlist_id = @uid";
cmd.Prepare();
cmd.Parameters.AddWithValue("@npw", newpw);
cmd.Parameters.AddWithValue("@opw", row["ibis_pw_userlist_currpw"].ToString());
cmd.Parameters.AddWithValue("@uid", row["ibis_pw_userlist_id"].ToString());
cmd.ExecuteNonQuery();
}
catch (MySqlException mysqle)
{
MessageBox.Show("mysql ERROR: " + mysqle.ToString());
return;
}
catch (Exception m1ex)
{
MessageBox.Show("M1_ERROR: " + m1ex.ToString());
return;
}
}
}
dbh.Close();
}
}
示例11: btnPrintPWMemos_Click
private void btnPrintPWMemos_Click(object sender, EventArgs e)
{
app = new Microsoft.Office.Interop.Word.Application { Visible = false };
System.Data.DataTable dt = new System.Data.DataTable();
string qry = "SELECT * FROM ibis_pw_userlist WHERE ibis_pw_userlist_active = 1";
using (MySqlConnection dbh = new MySqlConnection(Properties.Resources.DB_CONNSTR_HES))
{
dbh.Open();
using (MySqlDataAdapter da = new MySqlDataAdapter(qry, dbh))
{
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
doc = app.Documents.Add(@"C:\Users\dc1_000\Documents\HoldenEngineering\pw_memo_template.docx");
doc.Activate();
doc.Bookmarks["bmNameLbl"].Range.Text = row["ibis_pw_userlist_label"].ToString();
doc.Bookmarks["bmGenPW"].Range.Text = row["ibis_pw_userlist_currpw"].ToString();
doc.Bookmarks["bmUserName"].Range.Text = row["ibis_pw_userlist_un"].ToString();
doc.Bookmarks["bmOldPW"].Range.Text = row["ibis_pw_userlist_prevpw"].ToString();
doc.Bookmarks["bmNewPW"].Range.Text = row["ibis_pw_userlist_currpw"].ToString();
doc.Bookmarks["bmNewPW2"].Range.Text = row["ibis_pw_userlist_currpw"].ToString();
doc.PrintOut();
((Microsoft.Office.Interop.Word._Document)doc).Close(false, ref missing, ref missing);
}
}
dbh.Close();
}
}
示例12: cmdViewContracts_Click
//.........这里部分代码省略.........
}
}
catch (Exception ex)
{
return;
}
//Ghi hop dong ra file
if (cbxLoaiHD.Text == "Cho vay")
{
if (maloaiKH == 1)
//Khach hang doanh nghiep
//sourcefile = @"E:\Project\SVN\quanlydongtien\Source\Quanlydongtien\Quanlydongtien\bin\Temp\Hopdong\Khachhangdoanhnghiep.doc";
sourcefile = @dirWork + "\\Temp\\Hopdong\\Chovay\\Khachhangdoanhnghiep.doc";
else
//Khach hang ca nhan
sourcefile = @dirWork + "\\Temp\\Hopdong\\Chovay\\Khachhangcanhan.doc";
}
else
{
if (maloaiKH == 1)
sourcefile = @dirWork + @"\Temp\Hopdong\Huydong\Khachhangdoanhnghiep.doc";
else sourcefile = @dirWork + @"\Temp\Hopdong\Huydong\Khachhangcanhan.doc";
}
if (cbxLoaiHD.Text == "Cho vay")
destfile = @dirWork + @"\Contracts\Chovay\" + mahd + "_" + strDate + ".doc";
else destfile = @dirWork + @"\Contracts\Huydong\" + mahd + "_" + strDate + ".doc"; ;
object missing = Type.Missing;
try
{
doc = word.Documents.Open(ref sourcefile, 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();
if (!Utilities.Replace_String_In_Word_File(ref doc, "#TEN KHACH HANG#", benvay))
{
doc.Close(ref missing, ref missing, ref missing);
word.Application.Quit(ref missing, ref missing, ref missing);
return;
//doc.SaveAs(ref destfile, 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);
}
if (!Utilities.Replace_String_In_Word_File(ref doc, "#Dia chi khach hang#", Diachi))
{
doc.Close(ref missing, ref missing, ref missing);
word.Application.Quit(ref missing, ref missing, ref missing);
}
if (!Utilities.Replace_String_In_Word_File(ref doc, "#Dien thoai#", soDT))
{
doc.Close(ref missing, ref missing, ref missing);
word.Application.Quit(ref missing, ref missing, ref missing);
}
if (!Utilities.Replace_String_In_Word_File(ref doc, "#Tong so tien#", sotien))
{
doc.Close(ref missing, ref missing, ref missing);
word.Application.Quit(ref missing, ref missing, ref missing);
}
if (!Utilities.Replace_String_In_Word_File(ref doc, "#Laisuat#", laisuat))
{
doc.Close(ref missing, ref missing, ref missing);
word.Application.Quit(ref missing, ref missing, ref missing);
}