Excel-DNA / Excel-DNA/ExcelDna

ExcelDNA get file name

Open
#659 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.5k
Forks
292
Avg merge
20d 12h
Merged PRs (30d)
1

Description

Dear ExcelDNA team,

Excel add-in is creating and ExcelDNA is being used.
In custom function, I am trying to get name of calling file.

The code works, but it **takes a long time to execute**.

Code:
```
public string Method()
{
var reference = (ExcelReference) XlCall.Excel(XlCall.xlfCaller);
var sheetName = (string) XlCall.Excel(XlCall.xlSheetNm, reference);

var path1 = XlCall.Excel(XlCall.xlfGetDocument, 2, sheetName);
var path2 = XlCall.Excel(XlCall.xlfGetDocument, 88, sheetName);

if (path1 is string && path2 is string)
{
var pStr1 = path1.ToString();
var pStr2 = MethodUsingApplication(path2.ToString());

// ...
}

// ...
}

private string MethodUsingApplication(string raw)
{
try
{
var fullName = _app?.Workbooks[raw]?.FullName;
return Path.GetFileName(fullName);
}
catch (Exception ex)
{
// ...
return raw;
}
}
```

Questions:
1. Are there potential disadvantages to this code implementation?
2. Are there any alternatives to this code?

Versions:
Excel: 2311 (Build 17029.20108)
ExcelDNA: 1.6.0
.NET: .NET Framework 4.8

Thanks in advance

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.