Skip to content

Parse Error in SetFormulaA1 when using external links. #400

@mwflach-LSI

Description

@mwflach-LSI

When using SetFormulaA1 to link to an external file, the string cannot contain the name "sheet" or you will get a ParseingException. In the code below, the first use of SetFormulaA1 will work because externalSheetName does not contain the work "sheet" but the second use will fail.

This was built with 0.105

// ... (your existing ClosedXML setup)

// Create a new workbook and worksheet
var wb = new XLWorkbook();
var ws = wb.Worksheets.Add("Sheet1");

// Assume you want to link to cell A1 on "DataSheet" in "ExternalData.xlsx"
string externalWorkbookName = "ExternalData.xlsx";
string externalSheetName = "DataShee_";  //Notice the name is NOT "Sheet"
string externalCellReference = "A1";

// Construct the formula string
string formula = $"='[{externalWorkbookName}]{externalSheetName}'!{externalCellReference}";

// Set the formula in cell A1 of your current worksheet
ws.Cell("A1").SetFormulaA1(formula);

// Recononstruct the formula string and change the name to include the word "Sheet"
externalSheetName = "DataSheet";
formula = $"='[{externalWorkbookName}]{externalSheetName}'!{externalCellReference}";

//This line will not build since formula contains the word "Sheet".
ws.Cell("A1").SetFormulaA1(formula);


// Save the workbook
wb.SaveAs("MyWorkbookWithExternalLink.xlsx");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions