Skip to content

Commit

Permalink
Dyn 5314 open xml (#13647)
Browse files Browse the repository at this point in the history
* Fix String display

* Adding Unit test

* Checking Formula
  • Loading branch information
jesusalvino authored and QilongTang committed Mar 26, 2024
1 parent 3909e39 commit 517bd45
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/Libraries/DSOffice/OpenXmlHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -228,7 +228,7 @@ internal static bool Write(string filePath, string sheetName, object[][] data, i
currentColumnIndex++;
continue;
}

SetCellValue(data[i][j], cell, sharedStringTable, stylesheet, writeAsString);
currentColumnIndex++;
}
Expand Down Expand Up @@ -396,8 +396,15 @@ private static object GetCellValue(Cell cell, SharedStringTable sharedStringTabl
}
else
{
// Default to raw string value for inline strings and unknown types.
return cell.InnerText;
if (cell.CellFormula == null)
{
// Default to raw string value for inline strings and unknown types.
return cell.InnerText;
}
else
{
return cell.CellValue.Text;
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion test/Libraries/DynamoMSOfficeTests/ExcelTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -1433,5 +1433,16 @@ public void ExportCSVTest()
//Confirm it's correct
Assert.AreEqual(data, Data.ImportCSV(fn));
}

[Test]
[Category("UnitTests")]
public static void OpemXML_ImportExcelTest()
{
string filePath = Path.Combine(TestDirectory, @"core\importExport\OpenXML-ImportExcel.xlsx");
var data = Data.OpenXMLImportExcel(filePath, "worksheet1", 0, 0, false);
string cellValueWithFormula = data[0][2].ToString();
string cellValueWithoutFormula = data[1][2].ToString();
Assert.AreEqual(cellValueWithFormula, cellValueWithoutFormula);
}
}
}
Binary file not shown.

0 comments on commit 517bd45

Please sign in to comment.