C++でWebアドレスからリンクされた画像を挿入する
Contents
[
Hide
]
時々、ワークシートにWeb(http://)から画像を挿入する必要があります。これを行うには、画像のURLとして指定し、表計算がMicrosoft Excelで開かれるたびに画像がダウンロードされます。 画像は実際にはExcel文書に物理的に埋め込まれていませんが、Webリソースを指し示しています。
Microsoft Excel の使用
Microsoft Excel(たとえば2007)で:
- 挿入メニューをクリックし、画像を選択します。
- 挿入画像ダイアログで画像のWebアドレスを指定します。
Aspose.Cells for C++を使用した例
Aspose.Cells for C++は、ShapeCollection::AddLinkedPicture(int upperLeftRow, int upperLeftColumn, int heightPixels, int widthPixels, System::String sourceFullName)メソッドを使用してリンクされた画像を追加することをサポートします。このメソッドはPictureオブジェクトを返します。
以下の例では、Webアドレスからリンクされた画像をワークシートに追加する方法を示しています。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook workbook;
// Insert a linked picture (from Web Address) to B2 Cell
U16String imageUrl(u"http://www.aspose.com/Images/aspose-logo.jpg");
Picture pic = workbook.GetWorksheets().Get(0).GetShapes().AddLinkedPicture(1, 1, 100, 100, imageUrl);
// Set the height and width of the inserted image
pic.SetHeightInch(1.04);
pic.SetWidthInch(2.6);
// Save the Excel file
U16String outputPath = outDir + u"outLinkedPicture.out.xlsx";
workbook.Save(outputPath);
std::cout << "Linked picture inserted successfully!" << std::endl;
Aspose::Cells::Cleanup();
}