怎样向word中插入图片?

josxhn 2010-11-15 08:33:13
图文混排,下面两种形式,图片居中就好,并且如果size超过A4页面的话自动缩小为合适尺寸

1)图文均换行
文字
图片
文字
图片
文字

2)图文均不换行
文字 图片 文字 图片 文字



...全文
1167 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
josxhn 2010-11-17
  • 打赏
  • 举报
回复
谢谢楼上各位帮顶!这个问题发了好几个贴都得不到解决,唉
fanbingyuan 2010-11-17
  • 打赏
  • 举报
回复
果断马克之
jerysab 2010-11-16
  • 打赏
  • 举报
回复
学习下。。。。。。。
guoyanhong1111 2010-11-16
  • 打赏
  • 举报
回复
好,我帮你顶!
理不完的逻辑 2010-11-16
  • 打赏
  • 举报
回复
学习一下,不错~!
a505149061 2010-11-16
  • 打赏
  • 举报
回复
顶……………………
josxhn 2010-11-16
  • 打赏
  • 举报
回复
默默地顶
小海贼 2010-11-15
  • 打赏
  • 举报
回复
word 中有个方法,就是先将要编辑的内容设置成一个网页(html)形式,,这个你可以控制吧
然后word类中有提供个方法,好像是什么 insertXXXX的把这个网页直接插入进去,以前我做类似的事情,中有想过很好
josxhn 2010-11-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 q107770540 的回复:]

[/Quote]

谢谢,插入图片我是会做的。无法解决的问题是图文混排


public void InsertImage2(string imageFile)
{
object Range = System.Reflection.Missing.Value;

wdDoc.Paragraphs.Last.Range.Text = "text1";
wdDoc.Paragraphs.Add(ref Nothing);
wdDoc.Paragraphs.Last.Range.Text = "text2";

//Start Word and create a new document.
wdApp.Selection.Font.Bold = 1;
wdApp.Selection.Font.Size = 18;
wdApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
wdApp.Selection.InlineShapes.AddPicture(imageFile , ref Nothing , ref Nothing , ref Range);

}


以上代码我预期的效果是:

text1
text2
图片

结果输出以后变成

图片
text1
text2

即图片定位问题,求教
q107770540 2010-11-15
  • 打赏
  • 举报
回复


函数:

oWord.Selection.InlineShapes.AddPicture(ref name,ref LinkToFile,ref SaveWithDocument,ref Range);

示例:

object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
object name= "d:\\myfile.doc";
object Range=System.Reflection.Missing.Value;

//Start Word and create a new document.
Word.Application oWord;
Word.Document oDoc;
oWord = new Word.ApplicationClass();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,ref oMissing, ref oMissing);
oWord.Selection.Font.Bold = 1;
oWord.Selection.Font.Size=18;
oWord.Selection.ParagraphFormat.Alignment =Word.WdParagraphAlignment.wdAlignParagraphCenter;
oWord.Selection.InlineShapes.AddPicture("e:/picture/123.jpg",ref oMissing,ref oMissing,ref Range);

http://topic.csdn.net/t/20060408/12/4672092.html
josxhn 2010-11-15
  • 打赏
  • 举报
回复
怎样实现 :

图片 文字 图片 文字


这样在同一行中的图文混排
josxhn 2010-11-15
  • 打赏
  • 举报
回复
分段换行混排已经实现了,想知道不换行图文混排怎么做

			object Range = System.Reflection.Missing.Value;

wdDoc.Paragraphs.Last.Range.Text = "text1";
wdDoc.Paragraphs.Add(ref Nothing);
wdDoc.Paragraphs.Last.Range.Text = "text2";

//插入图片要用到Selection对象,所以应新建一个段落,然后在插入段落处调用Select()函数
wdDoc.Paragraphs.Add(ref Nothing);
wdDoc.Paragraphs.Last.Range.Select();

//Start Word and create a new document.
wdApp.Selection.Font.Bold = 1;
wdApp.Selection.Font.Size = 18;
wdApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
wdApp.Selection.InlineShapes.AddPicture(imageFile , ref Nothing , ref Nothing , ref Range);


110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧