这是原图
变成了这样的了:
这样就看的不是很清楚了,我将word 中的这部分图另存出来的时候如何保持原样呢
变成了这样的了:
这样就看的不是很清楚了,我将word 中的这部分图另存出来的时候如何保持原样呢
解决方案 »
- dataGridView 整行选中问题
- unsafe和fixed可以用于在类的字段中定义指针吗?另外在C#中用什么删除释放指针
- 如何知道Dictionary使用的内存大小
- 在线答题系统中的RadioButtonList问题
- 静态页面提交给静态页面和动态页面有区别吗?
- 在C#中如何將Access數據庫的某個表改名?
- winform传datagrid问题
- 做一个抓网页的WinForm程序,如何模拟ASPX的__doPostBack?
- 郁闷打印问题,请高手指教-----非常郁闷
- 怎么求正态分布的随机变量
- 3DES加密,代码得出的结果跟在线加密得出的结果不一致
- ashx一般应用处理程序接收音频文件,并保存到服务器
public static void add()
{
object Nothing = System.Reflection.Missing.Value;
object filename = "D:\\公式测试.docx";
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(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); //循环文章中的各个章节
foreach (Microsoft.Office.Interop.Word.Paragraph item in WordDoc.Paragraphs)
{
if (item != null)
{
if (item.Range.Text.Trim() != "")
{
//判断该范围内是否存在图片
if (item.Range.InlineShapes.Count != 0)
{
foreach (Microsoft.Office.Interop.Word.InlineShape shape in item.Range.InlineShapes)
{
//判断公式类型
if (shape.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeEmbeddedOLEObject)
{ //利用剪贴板保存数据
shape.Select(); //选定当前图片
WordApp.Selection.Copy();//copy当前图片
//使用剪切板
if (Clipboard.ContainsImage())
{
//用bitmap另存图片
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Clipboard.GetImage());
//定义文件路径
String path = "D:\\images\\";
//如果文件路径不存在就创建
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
//定义图片名称
String fileName = System.Guid.NewGuid() + ".png";
//保存图片
bmp.Save(path + fileName, System.Drawing.Imaging.ImageFormat.Png);
bmp.Dispose();
//获取当前文档额selection
var mySel = WordApp.Selection;
var anchor = mySel.Range; //获取所在光标的range对象
//添加图片
InlineShape inlineShape = WordDoc.InlineShapes.AddPicture(path + fileName, false, true, anchor);
//设置嵌入
inlineShape.ConvertToShape().WrapFormat.Type = WdWrapType.wdWrapInline;
//删除原图
shape.Delete();
}
}
}
} }
}
} WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
}