Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-5297 Import Excel Small Numbers #13680

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Libraries/DSOffice/OpenXmlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private static object GetCellValue(Cell cell, SharedStringTable sharedStringTabl
else
{
// This is a number
if (cell.CellValue.TryGetDouble(out var value))
if (double.TryParse(cell.CellValue.InnerText, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out var value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we tested change in behavior when digit separator is changed (from OS settings)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible use case: customer distributes a spreadsheet with per-cell number formatting to at least 2 different users in 2 different locations with different OS settings relating to number formatting (digit separator). Did the previous function work for both OS settings and does the new one not work the same?

{
if (readAsString)
{
Expand Down
17 changes: 16 additions & 1 deletion test/Libraries/DynamoMSOfficeTests/OpenXmlTests.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 @@ -240,6 +240,21 @@ public void TestFormula()
AssertPreviewValue(node.GUID.ToString(), data2);
}

[Test]
public void TestScientificNotationAsADoubleValue()
{
string testDir = TestDirectory;
string openPath = Path.Combine(testDir, @"core\excel\scientificNotation_OpenXml.dyn");
ViewModel.OpenCommand.Execute(openPath);

var node = ViewModel.Model.CurrentWorkspace.Nodes.First(n => n.Name == "Data.OpenXMLImportExcel");
ViewModel.HomeSpace.Run();

Assert.IsTrue(node.CachedValue.IsCollection);
var data2 = new object[] { new object[] { 1, 0.5d }, new object[] { 2, 0.00000000005d }, new object[] { 3, 0.0005 }, new object[] { 4, 0.05d }, new object[] { 5, 0.00000003 }, new object[] { 6, 0.0000000000000000002 } };
AssertPreviewValue(node.GUID.ToString(), data2);
}

#endregion


Expand Down
Binary file added test/core/excel/ScientificNotation.xlsx
Binary file not shown.
221 changes: 221 additions & 0 deletions test/core/excel/scientificNotation_OpenXml.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"Uuid": "3c9d0464-8643-5ffe-96e5-ab1769818209",
"IsCustomNode": false,
"Description": "",
"Name": "scientificNotation_OpenXml",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "\"Sheet1\";",
"Id": "21a38b9d21544217bd909348ef6bc4ec",
"Inputs": [],
"Outputs": [
{
"Id": "74b57c13c01d482eab46dedc5d14100d",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
},
{
"ConcreteType": "CoreNodeModels.Input.Filename, CoreNodeModels",
"HintPath": "C:\\Users\\filipe.otero\\Documents\\Code\\filipeotero\\Dynamo\\test\\core\\excel\\ScientificNotation.xlsx",
"InputValue": ".\\ScientificNotation.xlsx",
"NodeType": "ExtensionNode",
"Id": "979b38590a7e4cc18e0fb8c2faaaf9c7",
"Inputs": [],
"Outputs": [
{
"Id": "a4e947353bff42289ea6dc737dfda2ed",
"Name": "",
"Description": "File Path",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows you to select a file on the system and returns its file path"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"NodeType": "FunctionNode",
"FunctionSignature": "DSOffice.Data.OpenXMLImportExcel@string,string,int,int,bool",
"Id": "f5e38490fa1c4411b87346ddd9571627",
"Inputs": [
{
"Id": "0b1415ac08294ab0b58cc6e1837a4897",
"Name": "filePath",
"Description": "File representing the Excel workbook\n\nstring",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "b4d4f94084ff4ddf858ee58c6adaceae",
"Name": "sheetName",
"Description": "Name of the worksheet containing data\n\nstring",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "ae3e30579803435f84a62be8d80970c5",
"Name": "startRow",
"Description": "Start row for reading data. Enter 0 for Row 1, 1 for Row 2, etc.\n\nint\nDefault value : 0",
"UsingDefaultValue": true,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "e6fcfa9f4f344e3682ec94516d6e7a17",
"Name": "startColumn",
"Description": "Start column for reading data. Enter 0 for Column A, 1 for Column B, etc.\n\nint\nDefault value : 0",
"UsingDefaultValue": true,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "c27076c32b624d13ae8e65ffd8cec215",
"Name": "readAsString",
"Description": "Toggle to read cells as strings\n\nbool\nDefault value : false",
"UsingDefaultValue": true,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "66f7dc30ca2647eb8f7890efba03c09e",
"Name": "data",
"Description": "Rows of data from the Excel worksheet",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Auto",
"Description": "Read data from a Microsoft Excel spreadsheet by using the Open XML standard. Data is read by row and returned in a series of lists by row. Rows and columns are zero-indexed; for example, the value in cell A1 will appear in the data list at [0,0].\n\nData.OpenXMLImportExcel (filePath: string, sheetName: string, startRow: int = 0, startColumn: int = 0, readAsString: bool = false): var[][]"
}
],
"Connectors": [
{
"Start": "74b57c13c01d482eab46dedc5d14100d",
"End": "b4d4f94084ff4ddf858ee58c6adaceae",
"Id": "4e4db9b2285f4bd5a31050e439b79d2b",
"IsHidden": "False"
},
{
"Start": "a4e947353bff42289ea6dc737dfda2ed",
"End": "0b1415ac08294ab0b58cc6e1837a4897",
"Id": "2338f58a02464feead68ee51e52485b8",
"IsHidden": "False"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [
{
"Name": "ScientificNotation.xlsx",
"ReferenceType": "External",
"Nodes": [
"979b38590a7e4cc18e0fb8c2faaaf9c7"
]
}
],
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.18",
"Data": {}
}
],
"Author": "None provided",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.18.0.2986",
"RunType": "Manual",
"RunPeriod": "1000"
},
"Camera": {
"Name": "_Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"ConnectorPins": [],
"NodeViews": [
{
"Name": "Code Block",
"ShowGeometry": true,
"Id": "21a38b9d21544217bd909348ef6bc4ec",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 25.0,
"Y": 258.0
},
{
"Name": "File Path",
"ShowGeometry": true,
"Id": "979b38590a7e4cc18e0fb8c2faaaf9c7",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 67.0,
"Y": 27.999999999999957
},
{
"Name": "Data.OpenXMLImportExcel",
"ShowGeometry": true,
"Id": "f5e38490fa1c4411b87346ddd9571627",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 412.2000000000001,
"Y": 51.600000000000065
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}