http://www.c-sharpcorner.com/Code/2002/Mar/WordFromDotNet.asp
解决方案 »
- 关于事务的问题
- C# 实现的串口通讯软件 存在波特率、数据位、停止位不能用为什么(新手现在没有分数,我赚足了一定给)
- vb转换为C#,我改了但还是有问题,谁能帮帮我?
- 懂mouse_event这个模拟鼠标API的高人快来帮忙啊!!!!!!!!!!!!!!!!!!
- cannot start debugging .unable to find Microsoft Internet Explorer.
- 关于ToString的问题
- 提问,刚学C#大家帮忙
- C#winform实现语音采集并实时播放,出现了问题请教一下
- 各位大虾,在winform中如何做成圆形的按钮?
- 如何给集合添加可写属性?
- 在线等待~~
- 软件部署的问题,请指教
TitleQuery theQueryDialog = new TitleQuery();
if (theQueryDialog.ShowDialog() == DialogResult.OK)
{
// vba code to remind me how to do it.
// Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
// Selection.Font.Bold = wdToggle
// Selection.TypeText Text:="Creating a Title"
// Documents.Add Template:="C:\My Documents\CSharp Book Project\Normal.dot", _
// NewTemplate:=False, DocumentType:=0
object missing = System.Reflection.Missing.Value;
object fileName = "normal.dot";
object newTemplate = false;
object docType = 0;
object isVisible = true;
Word.Document aDoc = WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);
WordApp.Visible = true;
aDoc.Activate();
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
WordApp.Selection.Font.Bold = (int)Word.WdConstants.wdToggle;
WordApp.Selection.TypeText(theQueryDialog.Title);
//打开
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
object fileName = openFileDialog1.FileName;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value; // WordApp.Activate();
WordApp.Visible = true; Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing,ref readOnly,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing); aDoc.Activate(); WordApp.Selection.TypeText("Copyright C# Corner");
WordApp.Selection.TypeParagraph(); }
int rowIndex=1;
int colIndex=0; word.Application.Workbooks.Add(true);
DataTable table=GetData();
//将所得到的表的列名,赋值给单元格
foreach(DataColumn col in table.Columns)
{
colIndex++;
word.Cells[1,colIndex]=col.ColumnName;
} //同样方法处理数据
foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
word.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
//不可见,即后台处理
word.Visible=true;
}