110,567
社区成员
发帖
与我相关
我的任务
分享
Excel.Application excel1 = new Excel.Application();
Excel.Workbook wkb = excel1.Workbooks.Add(Type.Missing);
Excel.Worksheet sheet1 = wkb.Worksheets[1] as Excel.Worksheet;
Excel.Range range1 = sheet1.get_Range("G5:I6",Type.Missing) as Excel.Range;//.Cells[7, 8] as Excel.Range;
int row = 8;
IDataObject iData = Clipboard.GetDataObject();
Excel.Shape s = sheet1.Shapes.Item(row) as Excel.Shape;//这一句出问题 提示错误:不允许进入指定汇编中的索引
s.CopyPicture(Appearance.Button, Excel.XlCopyPictureFormat.xlBitmap); //COPY到内存。
if (iData.GetDataPresent(DataFormats.Bitmap))
{
pictureBox1.Image = (Bitmap)iData.GetData(DataFormats.Bitmap); //从内存取值;
pictureBox1.Image.Save(string.Format(@"D:\kkkkkkkkkkkkkkkkkkk\-" + sheet1.Shapes.Count.ToString() + "-.jpg")); //保存。
}
else
{
pictureBox1.Image = null;
}
Excel.Range range = sheet1.Cells[7, 8] as Excel.Range;
//int row = 8;
IDataObject iData = Clipboard.GetDataObject();
//Excel.Shape s = sheet1.Shapes.Item(row) as Excel.Shape;
//Excel.Range range = s.BottomRightCell;
range.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
//判断剪贴板中是否存在图片,如果存在,则将图片显示到pictureBox1中
if (Clipboard.ContainsImage())
{
System.Drawing.Image image = Clipboard.GetImage();
pictureBox1.Image = image;
image.Save(string.Format(@"D:\kkkkkkkkkkkkkkkkkkk\-" + "hao" + "-.jpg")); //保存。
}
image1.Save(string.Format(@"D:\kkkkkkkkkkkkkkkkkkk\-" + "hao" + "-.jpg")); //保存。
//初始化excel对象
Excel.Application excel = new Excel.Application();
//打开xls文件(注意:后面的参数都用Type.Missing填充,表示使用参数的默认值)
Excel.Workbook wkb = excel.Workbooks.Open(path, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
Excel.Worksheet ws = wkb.Worksheets[1] as Excel.Worksheet;
for (int row = 1; row <= ws.UsedRange.Rows.Count; row++)
{
for (int col = 1; col <= ws.UsedRange.Columns.Count; col++)
{
Range rge = ws.Cells[row, col] as Range;
foreach (Excel.Shape sh in ws.Shapes)
{
Range rg = excel.get_Range(sh.TopLeftCell, sh.BottomRightCell);
if (excel.Intersect(rge, rg, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing) != null)
{
sh.CopyPicture(Appearance.Button, Excel.XlCopyPictureFormat.xlBitmap);
IDataObject data = Clipboard.GetDataObject();
//这条if语出错,报未将对象引用设置到对象的实例,晕了,大侠们,帮忙啊
if (data.GetDataPresent(DataFormats.Bitmap))
{
System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
image.Save("test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
}
}