Office中國(guó)論壇/Access中國(guó)論壇

 找回密碼
 注冊(cè)

QQ登錄

只需一步,快速開始

返回列表 發(fā)新帖
查看: 3567|回復(fù): 1
打印 上一主題 下一主題

【作業(yè)】05課-CA135B_Amas

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2014-4-12 22:40:41 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
  1. using Microsoft.Office.Tools.Ribbon;
  2. using Word = Microsoft.Office.Interop.Word;
  3. using System.Windows.Forms;


  4. namespace Lesson05
  5. {
  6.     public partial class Ribbon1
  7.     {
  8.         private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
  9.         {

  10.         }


  11.         //刪除所有嵌入式圖片
  12.         private void btnDelAllInlineShapes_Click(object sender, RibbonControlEventArgs e)
  13.         {
  14.             Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
  15.             if (doc.InlineShapes.Count > 0)
  16.             {
  17.                 foreach (Word.InlineShape shape in doc.InlineShapes)
  18.                 {
  19.                     shape.Delete();
  20.                 }
  21.             }
  22.             else
  23.             {
  24.                 MessageBox.Show("文檔沒(méi)有嵌入式圖片");
  25.             }

  26.         }


  27.         //插入簽名
  28.         private void btnInsertSignature_Click(object sender, RibbonControlEventArgs e)
  29.         {
  30.             Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
  31.             Word.Range range;

  32.             //判斷當(dāng)前文檔段落數(shù)是否滿足要求
  33.             if (doc.Paragraphs.Count < 3)
  34.             {
  35.                 //段落數(shù)小于3,提示在文檔尾添加
  36.                 DialogResult result = MessageBox.Show("文檔段落數(shù)小于3,\n是否在文檔尾添加簽名", "提示", MessageBoxButtons.YesNo);
  37.                 if (result == DialogResult.Yes)
  38.                 {
  39.                     range = doc.Range(doc.Content.End - 1, doc.Content.End - 1);
  40.                     range.InsertAfter("\n西西");
  41.                 }
  42.                 else
  43.                 {
  44.                     return;
  45.                 }
  46.             }

  47.                 //在第3段尾添加簽名
  48.             else
  49.             {
  50.                 int iEnd = (doc.Paragraphs[3].Range.End)-1;
  51.                 doc.Range(0, iEnd).InsertAfter("西西");
  52.             }
  53.         }
  54.     }
  55. }
復(fù)制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享分享 分享淘帖 訂閱訂閱
2#
 樓主| 發(fā)表于 2014-4-13 01:11:54 | 只看該作者
選作題:統(tǒng)一設(shè)置嵌入式圖片大小




  1. using Microsoft.Office.Tools.Ribbon;
  2. using Word = Microsoft.Office.Interop.Word;
  3. using System.Windows.Forms;


  4. namespace Lesson05
  5. {
  6.     public partial class Ribbon1
  7.     {

  8.         //統(tǒng)一嵌入式圖片大小
  9.         private void btnSetInlineShapesSize_Click(object sender, RibbonControlEventArgs e)
  10.         {
  11.             Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
  12.             if (doc.InlineShapes.Count > 0)
  13.             {
  14.                 frmSetShapesSize setDialog = new frmSetShapesSize();
  15.                 setDialog.ShowDialog();
  16.             }
  17.             else
  18.             {
  19.                 MessageBox.Show("文檔中沒(méi)有嵌入式圖片");
  20.             }


  21.         }


  22.     }
  23. }
復(fù)制代碼
  1. using System;
  2. using System.Windows.Forms;
  3. using Microsoft.Office.Interop.Word;
  4. using System.Text.RegularExpressions;

  5. namespace Lesson05
  6. {
  7.     public partial class frmSetShapesSize : Form
  8.     {
  9.         Document doc = Globals.ThisAddIn.Application.ActiveDocument;
  10.         float height, width;


  11.         public frmSetShapesSize()
  12.         {
  13.             InitializeComponent();
  14.             radioButton1.Checked = true;
  15.             textBox1.Enabled = true;
  16.             radioButton2.Checked = false;
  17.             textBox2.Enabled = false;
  18.         }

  19.         private void textBox1_TextChanged(object sender, EventArgs e)
  20.         {
  21.             if (textBox1.Text != "" && IsNumber(textBox1.Text))
  22.             {
  23.                 height = Convert.ToSingle(textBox1.Text);
  24.             }
  25.         }

  26.         private void textBox2_TextChanged(object sender, EventArgs e)
  27.         {
  28.             if (textBox2.Text != "" && IsNumber(textBox2.Text))
  29.             {
  30.                 width = Convert.ToSingle(textBox2.Text);
  31.             }
  32.         }

  33.         //設(shè)置圖片大小
  34.         private void button1_Click(object sender, EventArgs e)
  35.         {
  36.             if (textBox1.Text == "" && textBox2.Text == "")
  37.             {
  38.                 MessageBox.Show("請(qǐng)輸入高度和寬度");
  39.                 return;
  40.             }

  41.             foreach (InlineShape shape in doc.InlineShapes)
  42.             {
  43.                 shape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
  44.                 if (radioButton1.Checked)
  45.                 {
  46.                     shape.Height = height;
  47.                     shape.ScaleWidth = shape.ScaleHeight;
  48.                 }

  49.                 if (radioButton2.Checked)
  50.                 {
  51.                     shape.Width = width;
  52.                     shape.ScaleHeight = shape.ScaleWidth;
  53.                 }
  54.             }
  55.             this.Dispose();
  56.         }

  57.         private void radioButton1_CheckedChanged(object sender, EventArgs e)
  58.         {
  59.             textBox1.Enabled = radioButton1.Checked;
  60.             textBox2.Text = "";
  61.         }

  62.         private void radioButton2_CheckedChanged(object sender, EventArgs e)
  63.         {
  64.             textBox2.Enabled = radioButton2.Checked;
  65.             textBox1.Text = "";
  66.         }


  67.         //判斷內(nèi)容是否為數(shù)字函數(shù)
  68.         public bool IsNumber(String strNumber)
  69.         {
  70.             Regex objNotNumberPattern = new Regex("[^0-9.-]");
  71.             Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
  72.             Regex objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*");
  73.             String strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
  74.             String strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
  75.             Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
  76.             return !objNotNumberPattern.IsMatch(strNumber) &&
  77.             !objTwoDotPattern.IsMatch(strNumber) &&
  78.             !objTwoMinusPattern.IsMatch(strNumber) &&
  79.             objNumberPattern.IsMatch(strNumber);
  80.         }

  81.       

  82.     }
  83. }
復(fù)制代碼

測(cè)試環(huán)境:WIN7 + VS2010 + OFFICE2010




本帖子中包含更多資源

您需要 登錄 才可以下載或查看,沒(méi)有帳號(hào)?注冊(cè)

x
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則

QQ|站長(zhǎng)郵箱|小黑屋|手機(jī)版|Office中國(guó)/Access中國(guó) ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2025-7-13 08:34 , Processed in 0.092017 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表