检查工作簿是否包含隐藏的外部链接 可能的使用场景
有时,工作簿包含在 Microsoft Excel 中无法查看的隐藏外部链接。Aspose.Cells 检索所有外部链接,无论它们是可见的还是隐藏的。但是,您可以检查 ExternalLink.IsVisible 属性,以检查外部链接是否可见。
检查工作簿是否包含隐藏的外部链接
以下示例代码加载了包含隐藏外部链接的 源 Excel 文件 。这些链接在 Microsoft Excel 中无法查看,但它们存在于工作簿中。在打印 ExternalLink.DataSource 和 ExternalLink.IsReferred 属性之后,它会打印 ExternalLink.IsVisible 属性。在下面的控制台输出中,您会看到所有外部链接都不可见。
示例代码
This file contains 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
// 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(CheckWorkbookContainsHiddenExternalLinks.class) + "articles/";
// Loads the workbook which contains hidden external links
Workbook workbook = new Workbook(dataDir + "CheckWorkbookContainsHiddenExternalLinks_in.xlsx");
// Access the external link collection of the workbook
ExternalLinkCollection links = workbook.getWorksheets().getExternalLinks();
// Print all the external links and check there IsVisible property
for (int i = 0; i < links.getCount(); i++) {
System.out.println("Data Source: " + links.get(i).getDataSource());
System.out.println("Is Referred: " + links.get(i).isReferred());
System.out.println("Is Visible: " + links.get(i).isVisible());
System.out.println();
控制台输出
以下是执行给定 示例 Excel 文件 时上述示例代码的控制台输出。
Copy Data Source : C : \ International \ DDB \ FAS 133 \ Swap Rates \ GS_1M_3M_1_2_5_ ¥ $_ ( B ) IRSwaps_0400 . xls
Is Referred : True
Is Visible : False
Data Source : C : \ DIST DAY \ MAY TEMPLATES \ 030601t . xls
Is Referred : True
Is Visible : False
Data Source : C : \ AREVIEW \ 2002 Controllable \ Autobrct . xls
Is Referred : True
Is Visible : False
Data Source : C : \ CARDSFO \ Main Files \ Rate Forecast \ FY 11 \ IFR 11 01 ( New Model REPORTS 11 . 08 . 07 ). xls
Is Referred : True
Is Visible : False