.net2003中,如何读取Word内容(包含表格,包含图片)并且插入到sqlserver数据库 c#中如何读取Word内容(包含表格,但不包含图片)并且插入到sqlserver数据库中?希望各位大哥帮忙啊!!!1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void ExportWord_Click(object sender, System.EventArgs e) { try { string savepath = ""; FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { savepath = folderBrowserDialog1.SelectedPath; } Object Nothing=System.Reflection.Missing.Value; object filename = savepath + "/" + StoreNum.Text + "库存报表"; Word.Application WordApp=new Word.ApplicationClass(); Word.Document WordDoc=WordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing); WordDoc.Paragraphs.First.Range.Text = "库存报表 [共有:" + storedt.Rows.Count.ToString() + "本书]"; WordDoc.Paragraphs.First.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,storedt.Rows.Count+1,6,ref Nothing,ref Nothing); table.Cell(1,1).Range.Text="ISBN号"; table.Cell(1,2).Range.Text="书名"; table.Cell(1,3).Range.Text="总库存"; table.Cell(1,4).Range.Text="借书库存"; table.Cell(1,5).Range.Text="可借数量"; table.Cell(1,6).Range.Text="已借数量"; for ( int i=0;i<storedt.Rows.Count;i++ ) { table.Cell(i+2,1).Range.Text = storedt.Rows[i]["Book_ISBN"].ToString(); table.Cell(i+2,2).Range.Text = storedt.Rows[i]["Book_Name"].ToString(); table.Cell(i+2,3).Range.Text = storedt.Rows[i]["Store_Num"].ToString(); table.Cell(i+2,4).Range.Text = storedt.Rows[i]["CanBorrow_Num"].ToString(); table.Cell(i+2,5).Range.Text = storedt.Rows[i]["InShop_Num"].ToString(); table.Cell(i+2,6).Range.Text = storedt.Rows[i]["OutShop_Num"].ToString(); } 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); WordDoc.Close(ref Nothing, ref Nothing, ref Nothing); WordApp.Quit(ref Nothing, ref Nothing, ref Nothing); parent.statusBar1.Panels[0].Text = "操作提示:库存报表导出成功"; } catch { parent.statusBar1.Panels[0].Text = "操作提示:库存报表导出失败"; } } 注意要引用Interop.Word.dll 多谢楼上大哥的代码,可是我现在遇到的问题是,我要做一个题库系统,允许用户在word里输入题目,如果题目中包含图片和表格,应该如何读取,并且插入到数据库中呢? 我曾经尝试过把一个word文档的内容读取到剪贴板中,然后再写到另一个word文档中,可是源文件中如果有图片和表格就写不到目标文档中,文字的东西写过去是没有问题,大家能不能给我一个解决的好办法啊,小弟拜谢了 嵌入在父窗口iframe里的子页面里的div被父窗口挡住 后台运行异常如何不影响主界面? WinForm: 与 大 家 分 享 个 奇 怪 的 现 象 SQl2000查询分析器报错问题,求救!!! 窗体关闭为何引发其他窗体同时关闭 求助,自定义控件无法显示 棘手问题,来者有分 c# 如何通过程序增加词条到已建立的语法中? List类型的属性怎样用SetValue赋值 SOS !Please help me ! asp.net and c# 中gif图片处理 如何导出数据库内容为EXCEL或.Txt文件?? 申明变量或者引用对象加个?是什么意思
{
try
{
string savepath = "";
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
savepath = folderBrowserDialog1.SelectedPath;
}
Object Nothing=System.Reflection.Missing.Value;
object filename = savepath + "/" + StoreNum.Text + "库存报表";
Word.Application WordApp=new Word.ApplicationClass();
Word.Document WordDoc=WordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);
WordDoc.Paragraphs.First.Range.Text = "库存报表 [共有:" + storedt.Rows.Count.ToString() + "本书]";
WordDoc.Paragraphs.First.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
Word.Table table=WordDoc.Tables.Add(WordApp.Selection.Range,storedt.Rows.Count+1,6,ref Nothing,ref Nothing);
table.Cell(1,1).Range.Text="ISBN号";
table.Cell(1,2).Range.Text="书名";
table.Cell(1,3).Range.Text="总库存";
table.Cell(1,4).Range.Text="借书库存";
table.Cell(1,5).Range.Text="可借数量";
table.Cell(1,6).Range.Text="已借数量";
for ( int i=0;i<storedt.Rows.Count;i++ )
{
table.Cell(i+2,1).Range.Text = storedt.Rows[i]["Book_ISBN"].ToString();
table.Cell(i+2,2).Range.Text = storedt.Rows[i]["Book_Name"].ToString();
table.Cell(i+2,3).Range.Text = storedt.Rows[i]["Store_Num"].ToString();
table.Cell(i+2,4).Range.Text = storedt.Rows[i]["CanBorrow_Num"].ToString();
table.Cell(i+2,5).Range.Text = storedt.Rows[i]["InShop_Num"].ToString();
table.Cell(i+2,6).Range.Text = storedt.Rows[i]["OutShop_Num"].ToString();
}
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);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
parent.statusBar1.Panels[0].Text = "操作提示:库存报表导出成功";
}
catch
{
parent.statusBar1.Panels[0].Text = "操作提示:库存报表导出失败";
}
}
注意要引用Interop.Word.dll