Skip to content

Commit 517bd45

Browse files
jesusalvinoQilongTang
authored andcommitted
Dyn 5314 open xml (#13647)
* Fix String display * Adding Unit test * Checking Formula
1 parent 3909e39 commit 517bd45

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/Libraries/DSOffice/OpenXmlHelper.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.IO;
@@ -228,7 +228,7 @@ internal static bool Write(string filePath, string sheetName, object[][] data, i
228228
currentColumnIndex++;
229229
continue;
230230
}
231-
231+
232232
SetCellValue(data[i][j], cell, sharedStringTable, stylesheet, writeAsString);
233233
currentColumnIndex++;
234234
}
@@ -396,8 +396,15 @@ private static object GetCellValue(Cell cell, SharedStringTable sharedStringTabl
396396
}
397397
else
398398
{
399-
// Default to raw string value for inline strings and unknown types.
400-
return cell.InnerText;
399+
if (cell.CellFormula == null)
400+
{
401+
// Default to raw string value for inline strings and unknown types.
402+
return cell.InnerText;
403+
}
404+
else
405+
{
406+
return cell.CellValue.Text;
407+
}
401408
}
402409
}
403410

test/Libraries/DynamoMSOfficeTests/ExcelTests.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
@@ -1433,5 +1433,16 @@ public void ExportCSVTest()
14331433
//Confirm it's correct
14341434
Assert.AreEqual(data, Data.ImportCSV(fn));
14351435
}
1436+
1437+
[Test]
1438+
[Category("UnitTests")]
1439+
public static void OpemXML_ImportExcelTest()
1440+
{
1441+
string filePath = Path.Combine(TestDirectory, @"core\importExport\OpenXML-ImportExcel.xlsx");
1442+
var data = Data.OpenXMLImportExcel(filePath, "worksheet1", 0, 0, false);
1443+
string cellValueWithFormula = data[0][2].ToString();
1444+
string cellValueWithoutFormula = data[1][2].ToString();
1445+
Assert.AreEqual(cellValueWithFormula, cellValueWithoutFormula);
1446+
}
14361447
}
14371448
}
Binary file not shown.

0 commit comments

Comments
 (0)