我的代码如下,可是图片的格式和位置怎么也不对,我想让图片插在数字974后面,另外版式也是不对,,枚举里wdWrapInline和wdWrapNone怎么都是"文字之上"呢?
请问各位大哥,分不多. private void button2_Click(object sender, EventArgs e)
{
try
{
killWordProcess();//结束WORD进程
Object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined book */
Object Nothing = System.Reflection.Missing.Value;
Directory.CreateDirectory("C:\\罐笼计算"); //创建文件所在目录
string name = "罐笼计算文档" + DateTime.Now.ToShortDateString() + ".doc";//18:28
object filename = "C:\\罐笼计算\\" + name; //文件保存路径
//创建Word文档
Word._Application WordApp = new Word.ApplicationClass();
Word._Document WordDoc = new Word.DocumentClass();
WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);//出现提示信息,因为前面必须加_
WordDoc.Activate(); Word.Paragraph oPara1;
oPara1 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara1.Range.Text = "1.5吨双层四车四绳罐笼计算方法";
//oPara1.Range.Font.Bold = 5;
oPara1.Range.Font.Size = 12;
oPara1.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.Range.InsertParagraphAfter(); Word.Paragraph oPara2;
oRng = WordDoc.Books.get_Item(ref oEndOfDoc).Range;
oPara2= WordDoc.Content.Paragraphs.Add(ref oRng);
oPara2.Range.Text = "荷重:MG1.7-9B 1.5米固定式矿车单重974kg,4辆矿车总重974";//图片插在这个位置(图片是个乘号)
//oPara2.Range.Font.Bold = 5;
oPara2.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
//oPara2.Range.InsertParagraphAfter(); /**/
//插入图片
string FileName = "F:\\罐笼\\Image\\乘号.JPG";//图片所在路径
object LinkToFile = true;
object SaveWithDocument = true;
//Object abc=WordApp.Selection.Range;
oRng = WordDoc.Paragraphs[2].Range;
//Word.Range wrdpic = WordDoc.Books.get_Item(ref oEndOfDoc).Range;//WordDoc.Books.get_Item(ref oEndOfDoc).Range;//WordDoc.Range(ref WordDoc.Paragraphs[10].Range.End, ref WordDoc.Paragraphs[10].Range.End);//注意Range的用法
WordDoc.Words.Last.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref oRng )
//WordApp.Selection.Books.get_Item(ref oEndOfDoc).Range.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref oRng);
WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 10f;//图片宽度
WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 10f;//图片高度
//设置图片版式
Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
s.WrapFormat.Type = Word.WdWrapType.wdWrapInline;//.wdWrapNone;//.wdWrapSquare;.wdWrapTopBottom;//.wdWrapTight;//.wdWrapThrough;//
//文件保存
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);
MessageBox.Show(name + "文档生成成功,以保存到C:'\'罐笼计算'\'下");
}
catch
{
MessageBox.Show("文件导出异常!");
}
}
请问各位大哥,分不多. private void button2_Click(object sender, EventArgs e)
{
try
{
killWordProcess();//结束WORD进程
Object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined book */
Object Nothing = System.Reflection.Missing.Value;
Directory.CreateDirectory("C:\\罐笼计算"); //创建文件所在目录
string name = "罐笼计算文档" + DateTime.Now.ToShortDateString() + ".doc";//18:28
object filename = "C:\\罐笼计算\\" + name; //文件保存路径
//创建Word文档
Word._Application WordApp = new Word.ApplicationClass();
Word._Document WordDoc = new Word.DocumentClass();
WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);//出现提示信息,因为前面必须加_
WordDoc.Activate(); Word.Paragraph oPara1;
oPara1 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara1.Range.Text = "1.5吨双层四车四绳罐笼计算方法";
//oPara1.Range.Font.Bold = 5;
oPara1.Range.Font.Size = 12;
oPara1.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.Range.InsertParagraphAfter(); Word.Paragraph oPara2;
oRng = WordDoc.Books.get_Item(ref oEndOfDoc).Range;
oPara2= WordDoc.Content.Paragraphs.Add(ref oRng);
oPara2.Range.Text = "荷重:MG1.7-9B 1.5米固定式矿车单重974kg,4辆矿车总重974";//图片插在这个位置(图片是个乘号)
//oPara2.Range.Font.Bold = 5;
oPara2.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
//oPara2.Range.InsertParagraphAfter(); /**/
//插入图片
string FileName = "F:\\罐笼\\Image\\乘号.JPG";//图片所在路径
object LinkToFile = true;
object SaveWithDocument = true;
//Object abc=WordApp.Selection.Range;
oRng = WordDoc.Paragraphs[2].Range;
//Word.Range wrdpic = WordDoc.Books.get_Item(ref oEndOfDoc).Range;//WordDoc.Books.get_Item(ref oEndOfDoc).Range;//WordDoc.Range(ref WordDoc.Paragraphs[10].Range.End, ref WordDoc.Paragraphs[10].Range.End);//注意Range的用法
WordDoc.Words.Last.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref oRng )
//WordApp.Selection.Books.get_Item(ref oEndOfDoc).Range.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref oRng);
WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 10f;//图片宽度
WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 10f;//图片高度
//设置图片版式
Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
s.WrapFormat.Type = Word.WdWrapType.wdWrapInline;//.wdWrapNone;//.wdWrapSquare;.wdWrapTopBottom;//.wdWrapTight;//.wdWrapThrough;//
//文件保存
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);
MessageBox.Show(name + "文档生成成功,以保存到C:'\'罐笼计算'\'下");
}
catch
{
MessageBox.Show("文件导出异常!");
}
}
解决方案 »
- 关于查询字段所有约束的sql语句,在线等
- mvc 简单问题
- 急啊,求高手指点下关于C#压缩文件的问题!
- C#面试题,请大侠帮忙看看!!
- C#爬虫程序中多线程怎么实现?
- 在.Net的解决方案和项目窗口中,到底如何组织各种文件才合适,哪些资料上有专门讲。例如各个窗体文件Form1.cs、Form2.cs、...,是否都放在项目下,窗体越来越多,这样存放是否合适。是否考虑将各个窗体按从主窗体开始进入层层打开的深度层层建立文件夹
- 为什么FormClosing事件会执行两次?
- 我的datagrid的属性最下方没有“属性生成器”?也没有columns属性?我没分了请帮帮忙啊!!!!
- WPF中如何获得当前richtextbox的光标所在位置
- 连接Mysql的问题 大家都近来看哦
- C#多线程如何刷新主界面?
- C#如何控制3DMAX导出的3D模型或文件
参考一下这个,我觉得应该是wdWrapTopBottom。
wdWrapNone Behind text.
wdWrapSquare Square.
wdWrapThrough Through.
wdWrapTight Tight.
wdWrapTopBottom Top and bottom.
我的研究结果是wdWrapInline 和wdWrapNone 是一样的.
//cShape.WrapFormat.Type = WdWrapType.wdWrapNone;
//wdWrapInline In line with text.
//wdWrapNone Behind text.
//wdWrapSquare Square.
//wdWrapThrough Through.
//wdWrapTight Tight.
//wdWrapTopBottom Top and bottom. cShape.LockAnchor = 0;
cShape.WrapFormat.Side = WdWrapSideType.wdWrapBoth; ////设置图片浮于文字之上 - 查阅WdWrapType的相关WdWrapType Enumeration
cShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
cShape.WrapFormat.Type = WdWrapType.wdWrapNone;