更新 #4 OP 迟来提供了准备他一直试图提取的图片示例的说明:
1) 转到 nbbclubsites.nl/club/8000/uitslagen 2) 点击“TKDmm, ronde 1 [1]” 3) 点击 -14- 13/3 4) 点击“BC Den Dungen-1” 5) 选择 de 4 和心形符号 6) 复制 Ctrl+C 7) 打开 Excel 并选择单元格 (1,1) 8) 过去 Ctrl+V 在单元格中您会看到单元格中的 4 并且心形符号锁定左上角
我这样做了,心符号粘贴到我的工作表中没有任何问题。之后,1 Insert Picture 项中的SavePicture 方法会正确提取红心符号并将其作为 .JPG 文件保存到磁盘。呵呵!
更新 #3 回答这个问题的一个问题是没有
有关如何插入 OP 电子表格中的图片的信息。迄今为止,
已经确定了三种不同的方法,即:
- 使用插入 - Excel 插入选项卡中的图片
- 使用插入 - Excel 插入选项卡中的对象
- 使用所选单元格上下文菜单中的插入注释
下面我展示了每种方法的代码示例。
1.插入 - 图片
procedure TForm1.InsertPicture;
begin
Worksheet.Pictures.Insert('C:\Users\ma\Pictures\photo-2.JPG');
end;
procedure TForm1.SavePicture;
var
Picture : OleVariant;
begin
Picture := Worksheet.Pictures[1];
Picture.Select;
Picture.Copy;
SaveClipboard;
end;
2。插入 - 对象
procedure TForm1.InsertAsObject;
begin
WorkSheet.OLEObjects.Add(Filename:='C:\Users\ma\Pictures\wall.bmp', Link :=False,
DisplayAsIcon:=False).Select;
end;
procedure TForm1.SaveObjectBmp;
var
Shape : OleVariant;
begin
Caption := IntToStr(WorkSheet.OleObjects.Count);
WorkSheet.OLEObjects[1].Select;
WorkSheet.OLEObjects[1].CopyPicture;
Shape := WorkSheet.OLEObjects[1].ShapeRange.Item(1);
Shape.CopyPicture(xlScreen, xlBitMap);
SaveClipboard;
end;
3.作为单元格注释插入
procedure TForm1.InsertCommentPicture;
var
Cell,
Comment : OleVariant;
begin
Cell := WorkSheet.Cells.Range['b2', 'b2'];
Comment := Cell.AddComment;
Comment.Shape.Fill.UserPicture('C:\Users\ma\Pictures\photo-2.JPG');
Comment.Visible := True;
end;
procedure TForm1.SaveCommentPicture;
var
Cell,
Comment,
Shape,
Picture : OleVariant;
begin
Cell := WorkSheet.Cells.Range['B2', 'B2'];
Comment := Cell.Comment;
Comment.Visible := True;
Shape := Comment.Shape;
Shape.CopyPicture(xlScreen, xlBitMap);
SaveClipBoard;
end;
SaveClipBoard 方法和 FormCreate 方法如下所示。 Excel, WorkBook
和 WorkSheet 都是表单的 OleVariant 成员。
procedure TForm1.SaveClipboard;
// With thanks to the author of http://delphi.cjcsoft.net/viewthread.php?tid=46877
var
myBitmap: TBitmap;
myJpegImg: TJpegImage;
SaveFileName: string;
begin
Caption := IntToStr(Clipboard.FormatCount) + ':' + IntToStr(Clipboard.Formats[0]);
SaveFileName := ExtractFilePath(FileName) + 'Saved.Jpg';
myBitmap := TBitmap.Create;
myJpegImg := TJpegImage.Create;
try
if Clipboard.HasFormat(cf_Bitmap) then
begin
myBitmap.Assign(clipboard);
myJpegImg.Assign(myBitmap);
myJpegImg.SaveToFile(SaveFileName);
end
else
ShowMessage('No graphic on the clipboard');
finally
myBitmap.FreeImage;
myJpegImg.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Excel := CreateOleObject('Excel.Application');
Excel.Visible := True;
FileName := ExtractFilePath(Application.ExeName) + 'PictureBook.Xlsx';
WorkBook := Excel.Workbooks.Open(FileName);
WorkSheet := WorkBook.ActiveSheet;
end;