检查工作簿是否包含隐藏的外部链接 可能的使用场景
有时,工作簿包含在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-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Loads the workbook which contains hidden external links
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
// Access the external link collection of the workbook
ExternalLinkCollection links = workbook.Worksheets.ExternalLinks;
// Print all the external links and check there IsVisible property
for (int i = 0; i < links.Count; i++)
{
Console.WriteLine("Data Source: " + links[i].DataSource);
Console.WriteLine("Is Referred: " + links[i].IsReferred);
Console.WriteLine("Is Visible: " + links[i].IsVisible);
Console.WriteLine();
}
控制台输出
这是执行给定源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