ExcelまたはOpenOfficeにハイパーリンクを挿入する
Contents
[
Hide
]
ハイパーリンクは、2つのエンティティ間のリンクを作成するために使用されます。特にウェブサイトを含め、誰もがハイパーリンクの使用に慣れています。
Aspose.Cells for Python via .NETを使用すると、開発者はMicrosoft Excelファイルでさまざまな種類のハイパーリンクを作成できます。このトピックでは、Aspose.Cells for Python via .NETでサポートされているハイパーリンクの種類とExcelファイルでの使用方法について説明します。
ハイパーリンクの追加方法
Aspose.Cells for Python via .NETを使用すると、開発者はAPIまたはデザイナースプレッドシート(ハイパーリンクが手動で作成され、その後Aspose.Cells for Python via .NETを使用して他のスプレッドシートにインポートされるスプレッドシート)を使用して、Excelファイルにハイパーリンクを追加できます。
Aspose.Cells for Python via .NETは、Microsoft Excelファイルを表すWorkbookを提供します。Workbookクラスには、Excelファイル内の各ワークシートにアクセスできるWorksheetCollectionが含まれています。ワークシートはWorksheetクラスで表されます。Worksheetクラスには、Excelファイルに異なるハイパーリンクを追加するためのさまざまなメソッドが提供されています。
URLへのリンクの追加方法
Worksheetクラスには、hyperlinksコレクションが含まれています。hyperlinksコレクションの各アイテムはHyperlinkを表します。hyperlinksコレクションのaddメソッドを呼び出すことで、URLへのハイパーリンクを追加できます。
- セル名、ハイパーリンクが追加されるセルの名前。
- 行数、このハイパーリンク範囲の行数。
- 列数、このハイパーリンク範囲の列数。
- URL、URLアドレス。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the first worksheet | |
worksheet = workbook.worksheets[0] | |
# Adding a hyperlink to a URL at "A1" cell | |
worksheet.hyperlinks.add("A1", 1, 1, "http:// Www.aspose.com") | |
# Saving the Excel file | |
workbook.save(dataDir + "output.out.xls") |
上記の例では、空のセルA1にURLへのハイパーリンクが追加されます。このような場合、セルが空の場合、URLアドレスもその空のセルの値として追加されます。セルが空でない場合は、ハイパーリンクが追加されても、セルの値はプレーンテキストのように見えます。それをハイパーリンクのように見えるようにするには、そのセルに適切な書式設定を適用します。
同じファイル内のセルへのリンクの追加方法
同じExcelファイルのセルにハイパーリンクを追加することができます。hyperlinksコレクションのaddメソッドは、内部および外部ハイパーリンクの両方に対して機能します。
- セル名、ハイパーリンクが追加されるセルの名前。
- 行数、このハイパーリンク範囲の行数。
- 列数、このハイパーリンク範囲の列数。
- URL、対象セルのアドレス。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Adding a new worksheet to the Workbook object | |
workbook.worksheets.add() | |
# Obtaining the reference of the first (default) worksheet | |
worksheet = workbook.worksheets[0] | |
# Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in | |
# The same Excel file | |
worksheet.hyperlinks.add("B3", 1, 1, "Sheet2!B9") | |
# Saving the Excel file | |
workbook.save(dataDir + "output.out.xls") |
外部ファイルへのリンクの追加方法
外部のExcelファイルにハイパーリンクを追加することができます。hyperlinksコレクションのaddメソッドは、以下のパラメータを取ります。
- セル名、ハイパーリンクが追加されるセルの名前。
- 行数、このハイパーリンク範囲の行数。
- 列数、このハイパーリンク範囲の列数。
- URL、対象のアドレス、外部のExcelファイル。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Adding a new worksheet to the Excel object | |
i = workbook.worksheets.add() | |
# Obtaining the reference of the newly added worksheet by passing its sheet index | |
worksheet = workbook.worksheets[i] | |
# Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in | |
# The same Excel file | |
worksheet.hyperlinks.add("A5", 1, 1, dataDir + "book1.xls") | |
# Saving the Excel file | |
workbook.save(dataDir + "output.out.xls") |