请问.net怎么读取word文档啊? RT现在我需要读取一个word文档,还要进行编辑。word里面有几万文字+N多图片,请问怎么可以将word文档(包括字体、图片)读取出来呢?跪求~~~有代码更好啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 object oFileName = @"C:\3.docx"; //路径,自己修改 object oReadOnly = true; object oMissing = System.Reflection.Missing.Value; Word._Application oWord; Word._Document oDoc; oWord = new Word.Application(); //oWord.Visible = true;//只是为了方便观察 oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.ActiveWindow.Selection.WholeStory(); oDoc.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); string mytext = data.GetData(DataFormats.Text).ToString(); oDoc.Close(); MessageBox.Show(mytext); 你这个明显只读取的是文字内容啊,返回string类型的,那图片呢? 可以这么写 /// <summary> /// 获取图片路径 /// </summary> /// <param name="bytes"></param> /// <returns></returns> public static string getSignatureFile(byte[] bytes) { string approveFile = Application.StartupPath + @"\temp\" + Guid.NewGuid() + ".bmp"; if (File.Exists(approveFile)) { File.Delete(approveFile); } try { Image img = new Bitmap(Image.FromStream(new MemoryStream((byte[])bytes)), 100, 40); img.Save(approveFile, System.Drawing.Imaging.ImageFormat.Bmp); return approveFile; } catch { return ""; } }调用 picture = getSignatureFile((byte[])二进制图片); if (!string.IsNullOrEmpty(picture )) { object bookName = "图片"; oDoc.Books.get_Item(ref bookName).Select(); oWord.Selection.InlineShapes.AddPicture(picture, ref missingValue, ref missingValue, ref missingValue); } http://shudonghe.blog.163.com/blog/static/18533834920113297493390/ winform关于datagridview显示问题请教 dataGridView 排序 数据库读写设计 防止用户重复导入文本到数据库的问题 c#.net做安装包的问题 如何在C# 2010中创建类库 如何用流打开bmp图片并且显示在窗体上??? C# 多线程问题 如何给ContextMenu 添加图片? 求用c#做打印代码 .net Picture效果问题 请高手回答: 一个关于RollBack()的问题一直没得到很好的回答.
object oFileName = @"C:\3.docx"; //路径,自己修改
object oReadOnly = true;
object oMissing = System.Reflection.Missing.Value; Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
//oWord.Visible = true;//只是为了方便观察
oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.ActiveWindow.Selection.WholeStory();
oDoc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
string mytext = data.GetData(DataFormats.Text).ToString();
oDoc.Close(); MessageBox.Show(mytext);
/// <summary>
/// 获取图片路径
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public static string getSignatureFile(byte[] bytes)
{
string approveFile = Application.StartupPath + @"\temp\" + Guid.NewGuid() + ".bmp";
if (File.Exists(approveFile))
{
File.Delete(approveFile);
}
try
{
Image img = new Bitmap(Image.FromStream(new MemoryStream((byte[])bytes)), 100, 40);
img.Save(approveFile, System.Drawing.Imaging.ImageFormat.Bmp);
return approveFile;
}
catch
{
return "";
} }调用
picture = getSignatureFile((byte[])二进制图片);
if (!string.IsNullOrEmpty(picture ))
{
object bookName = "图片";
oDoc.Books.get_Item(ref bookName).Select();
oWord.Selection.InlineShapes.AddPicture(picture, ref missingValue, ref missingValue, ref missingValue);
}