110,531
社区成员
发帖
与我相关
我的任务
分享
try
{
Object Nothing = System.Reflection.Missing.Value;
Directory.CreateDirectory("C:/CNSI"); //创建文件所在目录
string name = "CNSI_"+ ".doc";
object filename = "C://CNSI//" + name; //文件保存路径
//创建Word文档
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 12, 3, ref Nothing, ref Nothing);
newTable.Cell(1, 1).Range.Text = "产品详细信息表";
newTable.Cell(1, 2).Range.Text = "产品表";
newTable.Cell(1, 3).Range.Text = "产品特殊属性";
WordDoc.Content.Tables[1].Rows.Add(ref Nothing);
WordDoc.Content.Tables[1].Rows.Add(ref Nothing);
object myNothing = System.Reflection.Missing.Value;
object myFileName = filename;
object myWordFormatDocument = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
object myLockd = false;
object myPassword = "";
object myAddto = true;
try
{
WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
}
catch
{
throw new Exception("导出word文档失败!");
}
}
catch
{
MessageBox.Show("导出word文档失败!");
}