rt
解决方案 »
- 我前段时间做的一个小型网站,和SILVERLIGHT比较,大家看看怎么样??
- 操作SQL server2008 插入数据时出错,咋回事?
- Process是命名空间?
- 有一串"B1B1",它是汉字"北"的编码,现在我想把"B1B1"变成"北",打印出来,该怎么做?
- 指针计算 CSharp pointer
- vs 2005 能否支持C#3.0的技术
- 打印自定纸张问题,预览正常,打印后少了10行,请前辈指点.
- 如何得到系统所有的installed printers
- 思归请进~~~请教如何用.net技术推送技术
- 我的网站程序,前台采用flash,后台采用c#,已经完工一半,希望找合作者!
- sql server存取word文档的问题(急)
- progressbar进度条与事件不同步(全部结束之后事件没有结束),用PerformStep()方法
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using System.IO;
using System.Data.sqlClient;
using System.Data.OLEDB;
using System.Threading;
private void btnDoc_Click(object sender, System.EventArgs e)
{
ApplicationClass myWordApp = new ApplicationClass();
Document myWordDoc = new Document();
object filename = My.Computer.FileSystem.CurrentDirectory() + "\\Template\\dt.dot";
object cd = " ";
object code1 = "书名";
object code2 = "标题 1";
object code3 = "标题 2";
object code4 = "正文";
sfd.Filter = "Word 文档|*.DOC";
sfd.Title = "保存作业文档";
sfd.FileName = this.Label1.Text.Replace("\\", "_") + ".doc";
sfd.ShowDialog();
if (sfd.FileName != "") {
object destination = sfd.FileName;
//My.Computer.FileSystem.CurrentDirectory() + "\Docs\" + Me.Label1.Text.Replace("\", "_") + ".doc"
object notTrue = false;
object missing = System.Reflection.Missing.Value;
try {
myWordApp.Visible = true;
myWordDoc = myWordApp.Documents.Add(filename, missing, missing, missing);
object pgb = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
myWordApp.Selection.Select();
myWordApp.Selection.TypeParagraph();
myWordApp.Selection.TypeParagraph();
myWordDoc.SaveAs(destination, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
myWordDoc.Close(notTrue, missing, missing);
myWordApp.Application.Quit(notTrue, missing, missing);
myWordApp = null;
Thread.Sleep(1);
}
catch {
Interaction.MsgBox("请安装 ms office 2003,本操作需要该系统。", MsgBoxStyle.Information, "提示");
}
finally {
MessageBox.Show(this, "生成文档完成!");
}
}
GC.Collect();
}