|
楼主 |
发表于 2016-1-22 22:13
|
显示全部楼层
测试成功,主要代码如下:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Text.RegularExpressions;//用于button1_Click的代码引用正则Regex.Split
- namespace ExcelHelpTaskPane
- {
- public partial class Form6 : Form
- {
- public Form6()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Microsoft.Office.Interop.Excel.Range cel = Globals.ThisAddIn.Application.ActiveCell;
- try
- {
- //string s = Globals.ThisAddIn.Application.InputBox("", Type: 8);
- string s = Globals.ThisAddIn.Application.InputBox("", "", "<a、<b、<div、...<table...");
- String s2 = "";
- if (s != null)
- {
- s2 = s.Replace("<", "</");
- }
- else
- {
- s2 = "<body";
- s = "<body";
- }
- int r = 0;
- foreach (var t in Regex.Split(cel.Text, " "))
- {
- r = r + 1;
- cel.Cells[r, 1].Value = Regex.Split(t, s)[0];
- int r2 = 0;
- foreach (var t2 in Regex.Split(t, s))
- {
- r2 = r2 + 1;
- if (r2 > 1)
- {
- r = r + 1;
- cel.Cells[r, 1].Value = s + Regex.Split(t2, s2)[0];
- int r3 = 0;
- foreach (var t3 in Regex.Split(t2, s2))
- {
- r3 = r3 + 1;
- if (r3 > 1)
- {
- r = r + 1;
- cel.Cells[r, 1].Value = s2 + t3;
- }
- }
- }
- }
- }
- }
- catch (Exception exception)
- {
- MessageBox.Show(exception.Message);
- }
- }
- }
- }
复制代码 |
|