代码如下:
if (!markValues.Contains(key))
{//判断是否包含书签
continue;
}
DataTable imgtb = markValues[key] as DataTable;
float heights = 0;
//将光标定位到书签内。
bm.Select(); //定位到数千位置
//得到光标的位置。
wordSelection = wordApplication.Selection;
Microsoft.Office.Interop.Word.WdParagraphAlignment wdparagraph = wordSelection.ParagraphFormat.Alignment;
wordSelection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
if (imgtb != null && imgtb.Rows.Count > 0)
{
for (int i = 0; i < imgtb.Rows.Count; i++)
{
byte[] bytes = imgtb.Rows[i]["CONTENT"] as byte[];
string id = imgtb.Rows[i]["ID"] as string;
if (bytes != null && !string.IsNullOrEmpty(id))
{
wordSelection.TypeParagraph();
object range = wordSelection.Range;
object objMissing = System.Reflection.Missing.Value;
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML; // 图片嵌入word里面,成为一体保存
object linkToFile = Microsoft.Office.Interop.Word.WdLinkType.wdLinkTypePicture;
imgPath = @"C:\Users\zx\Desktop\ftpDown.jpg"; //图片路径
Microsoft.Office.Interop.Word.InlineShape shape = wordSelection.InlineShapes.AddPicture(imgPath, ref linkToFile, ref format, ref range);
//shape.Width = w;//图片宽度
//shape.Height = h;//图片高度
shape.ConvertToShape().WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;
wordSelection.TypeParagraph();
}
}
}
插入后效果:
到底哪里出了问题呢???代码中如何设置呢????
百里加急~~~~
3 个解决方案
#1
// 摘要:
// Wraps text around the shape. Line continuation is on the opposite side of
// the shape.
wdWrapSquare = 0,
//
// 摘要:
// Tight.
wdWrapTight = 1,
//
// 摘要:
// Through.
wdWrapThrough = 2,
//
// 摘要:
// Behind text.
wdWrapNone = 3,
//
// 摘要:
// Places shape in front of text.
wdWrapFront = 3,
//
// 摘要:
// Top and bottom.
wdWrapTopBottom = 4,
//
// 摘要:
// Places shape behind text.
wdWrapBehind = 5,
//
// 摘要:
// In line with text.
wdWrapInline = 7,
上面的 枚举到底哪一个才和下图的 嵌入型对应呢???
#2
1:在 wordSelection.TypeParagraph();上面加下面这句
shape.ConvertToShape().ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
wordSelection.TypeParagraph();
2:第一个方法不行的话,则把wordSelection.TypeParagraph();去掉在试
3:再不行在设置图片格式那慢慢的一个一个试。
shape.ConvertToShape().ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
wordSelection.TypeParagraph();
2:第一个方法不行的话,则把wordSelection.TypeParagraph();去掉在试
3:再不行在设置图片格式那慢慢的一个一个试。
#1
// 摘要:
// Wraps text around the shape. Line continuation is on the opposite side of
// the shape.
wdWrapSquare = 0,
//
// 摘要:
// Tight.
wdWrapTight = 1,
//
// 摘要:
// Through.
wdWrapThrough = 2,
//
// 摘要:
// Behind text.
wdWrapNone = 3,
//
// 摘要:
// Places shape in front of text.
wdWrapFront = 3,
//
// 摘要:
// Top and bottom.
wdWrapTopBottom = 4,
//
// 摘要:
// Places shape behind text.
wdWrapBehind = 5,
//
// 摘要:
// In line with text.
wdWrapInline = 7,
上面的 枚举到底哪一个才和下图的 嵌入型对应呢???
#2
1:在 wordSelection.TypeParagraph();上面加下面这句
shape.ConvertToShape().ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
wordSelection.TypeParagraph();
2:第一个方法不行的话,则把wordSelection.TypeParagraph();去掉在试
3:再不行在设置图片格式那慢慢的一个一个试。
shape.ConvertToShape().ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
wordSelection.TypeParagraph();
2:第一个方法不行的话,则把wordSelection.TypeParagraph();去掉在试
3:再不行在设置图片格式那慢慢的一个一个试。