以前我写过一个向excel插入图片的方法~~
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
public static void InsertPicture(Image img, Excel.Worksheet sheet)
{
int lastUsedRow = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
int lastPictureRow = sheet.Shapes.OfType<Excel.Shape>().Max(p => p.BottomRightCell.Row);
int nextRow = Math.Max(lastUsedRow, lastPictureRow) + 1;
(sheet.Cells[nextRow, 1] as Excel.Range).Select();
Clipboard.SetImage(img);
sheet.Paste();
}
仅供参考~~
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
public static void InsertPicture(Image img, Excel.Worksheet sheet)
{
int lastUsedRow = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
int lastPictureRow = sheet.Shapes.OfType<Excel.Shape>().Max(p => p.BottomRightCell.Row);
int nextRow = Math.Max(lastUsedRow, lastPictureRow) + 1;
(sheet.Cells[nextRow, 1] as Excel.Range).Select();
Clipboard.SetImage(img);
sheet.Paste();
}
仅供参考~~
解决方案 »
- 数字 字母生成编号
- 急急急。。请问下关于动态绑定datagriview的问题。。。麻烦了。。
- GridView 取值问题 c#.net
- datagridview 树形显示的问题
- 截取函数求助
- 动态类型转换的问题
- DateTime的default的疑问
- ●●●●●●●●怎样在C#中判断系统中是否有ie6.0,Mdac2.7和.net框架的代码?
- boxing和unboxing到底有什么用?
- WinForm下的DevExpress中ComboxEdit如何绑定key/value值?
- 关于DataGridViewTextBoxColumn输入密码的问题
- C#中listbox删除出现未将对象引用设置到对象实例
看下组件的版本
在看下你试用EXL的版本
我不懂 纯瞎扯http://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.shapes.shape(v=vs.100).aspx
按照你的方法是可以插入的 但是还是会把之前的所有图片插入进去
prjitem = null; //这里调用前也做了清空 还是不行
prjitem = (Bitmap)Image.FromFile(dt.Rows[i][11].ToString());
InsertPicture(prjitem, sheet, "J1");
public static void InsertPicture(Image img, Microsoft.Office.Interop.Excel.Worksheet sheet,string cell)
{ Microsoft.Office.Interop.Excel.Range pic = sheet.get_Range(cell, Type.Missing);
pic.Select();
Clipboard.Clear(); //这里增加清空也没用
Clipboard.SetImage(img);
sheet.Paste();
}
image prjitem;
prjitem = Image.FromFile(dt.Rows[i][11].ToString());
//装入之后怎么调整大小