埋め込みOLEオブジェクトのクラス識別子を取得または設定する

可能な使用シナリオ

Aspose.Cellsは、埋め込みOLEオブジェクトのクラス識別子を取得または設定するために使用できるOleObject.ClassIdentifierプロパティを提供します。OLEオブジェクトのクラス識別子は実際にはGUID(グローバルユニーク識別子)です。 GUIDは常に16バイトの長さであり、そのためクラス識別子も16バイトの長さです。 これらはWindowsレジストリ内によく見られ、クライアントアプリケーション内のさまざまな埋め込まれたリソースを含む埋め込みOLEオブジェクトの開き方についてホストアプリケーションに情報を提供します。

埋め込まれたOLEオブジェクトのクラス識別子を取得または設定する

次のスクリーンショットは、埋め込まれたPowerPointのOLEオブジェクトを含むsample excel fileから読み取られた、つまりGUIDであるOLEオブジェクトのクラス識別子を示しています。

todo:image_alt_text

サンプルコード

次のサンプルコードは、サンプルエクセルファイルを使用して実行され、OLEオブジェクトのクラス識別子を出力するコンソール出力を示しています。表示されるGUIDは、スクリーンショット内に表示されるものとまったく同じです。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(GetSettheClassIdentifier.class) + "articles/";
//Load your sample workbook which contains embedded PowerPoint ole object
Workbook wb = new Workbook(dataDir + "sample.xls");
//Access its first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first ole object inside the worksheet
OleObject oleObj = ws.getOleObjects().get(0);
//Get the class identifier of ole object in bytes and convert them into GUID
byte[] classId = oleObj.getClassIdentifier();
//Position of the bytes and formatting
int[] pos = {3, 2, 1, 0, -1, 5, 4, -1, 7, 6, -1, 8, 9, -1, 10, 11, 12, 13, 14,15};
StringBuilder sb = new StringBuilder();
for(int i=0; i<pos.length; i++)
{
if(pos[i]==-1)
{
sb.append("-");
}
else
{
sb.append(String.format("%02X", classId[pos[i]]&0xff));
}
}
//Get the GUID from conversion
String guid = sb.toString();
//Print the GUID
System.out.println(guid);

コンソール出力

これはサンプルエクセルファイルを使用して実行した上記サンプルコードのコンソール出力です。

 DC020317-E6E2-4A62-B9FA-B3EFE16626F4