最近比较闲了,考试也快要到了。但是编程技术方面还是不能掉啊.

现在开始VSTO编程之旅了。这个话题是连Blog的。所以有兴趣的Blog之友,技术之士,可以匿名或者非匿名的评论,交流。

对了,下面的代码都是本人写的,和积累的,每一个功能都是以Method的形式进行粘贴的,一般只有你懂的话,就可以直接调用的,当然一般都是从基础开始。

如果想和本人进行交流的话,我的首页上有我的MSN。。。。

正在话归正题----
VSTO[Excel]
//新建Sheet
private void CreditSheet()


{
Excel.Workbook newWorkbook = this.Application.Workbooks.Add(missing);
}

//打开Sheet
private void OpenSheet()


{
this.Application.Workbooks.Open(this.ImputFolderName.Text.ToString(), missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
}

//连续在多个单元格中显示文字,并调整各自单元格的宽度
private void AimatA1RangeUsingNameRange()

{
//设定一个NamedRange
NamedRange textInCell;
textInCell = this.Controls.AddNamedRange(this.get_Range("A8", missing), "EvaluateDemo");

//重新规定 NameRange [A8-D8]
textInCell.RefersTo = "=Sheet1!$A$8:$D$8";

//evaluate
textInCell.Value2 = "Hello world!";

//自动调整单元格
textInCell.Columns.AutoFit();
}

**此Value2 属性与 Value 属性的唯一区别在于,Value2 不是参数化属性。

private void FindMarthaInTheRange()

{
this.Range["H1", missing].Value2 = "Martha jone ";

NamedRange auto_HR =
this.Controls.AddNamedRange(this.Range["H2", missing],
"auto_HR");

//根据H1中的字符串自动从头查找并复制同样的值
auto_HR.Value2 = auto_HR.AutoComplete("Ma");

//自动调整单元格
auto_HR.Columns.AutoFit();
}

*在这里Martha jone 不能任意查找,意思就是AutoComplete(参数值),只能从头匹配,不能任意匹配。

//合并单元格
private void MergeRange()


{
NamedRange rangeOne = this.Controls.AddNamedRange(this.Range["A12", "D27"], "rangeOne");
rangeOne.Select();
rangeOne.Merge(false);
}

//设置Cells边框
private void setBordersAndInterior()

{
//第一种写法
NamedRange bordersRange = this.Controls.AddNamedRange(this.Range["E12","F12"], "borderRange");
bordersRange.Borders.LineStyle = Excel.XlLineStyle.xlSlantDashDot;
//Set Color
bordersRange.Interior.Color = 0xFF00;

//第二种写法
for (int i = 1; i <= 7; i++)

{
base.Range[base.Cells[i, 7], base.Cells[i, 8]].Borders.LineStyle = i;
}
}



AutoCalculate#region AutoCalculate
//自动计算
private void NotifyChanges()


{
NamedRange changesRange = this.Controls.AddNamedRange(this.Range["G2", "G8"], "compositeRange");
changesRange.Change += new DocEvents_ChangeEventHandler(changesRange_Change);
}

private void changesRange_Change(Range Target)


{
NamedRange namedRange2 =
this.Controls.AddNamedRange(this.Range["G9", missing],
"namedRange5");
//设置公式
namedRange2.Formula = "=SUM(G2:G8)";
namedRange2.FormulaHidden = true;
//计算
namedRange2.Calculate();
}

今天就到此吧。。。待续

#endregion
12月5日更新(快考试,要加油了)

问题1:为什么在单元格中输入一个19位或者更多位的数字,显示时数字不会以16进制的形式显示,如:1111E+9。想实现“以文本形式显示数字”?
答:只要设置一下此单元格NumberFormatLocal ="@" 即可
ex:
this.Range["A35", missing].NumberFormatLocal = "@";
this.Range["A35", missing].Value2 = "111111111111111111111111111111111111111111”;

问题2:想把当前活动窗口网格线去掉?
答:设置DisplayGridlines 为False即可。this.Application.ActiveWindow.DisplayGridlines = false;


posted @
2006-11-22 17:36
RicoRui
阅读(
2702)
评论()
编辑
收藏
举报