Skip to content

Commit

Permalink
DYN-7963 Obsolote Excel Interop Nodes (#15743)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGlobant20 authored Jan 12, 2025
1 parent 3d8a262 commit d1dd01f
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 53 deletions.
15 changes: 14 additions & 1 deletion src/Libraries/DSOffice/Excel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public static class Excel
/// <param name="file"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkBook ReadExcelFile(FileInfo file)
{
return WorkBook.ReadExcelFile(file.FullName);
}

[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkBook ReadExcelFile(string file)
{
return WorkBook.ReadExcelFile(file);
Expand All @@ -33,6 +35,7 @@ public static WorkBook ReadExcelFile(string file)
/// <param name="workbook"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkSheet[] GetWorksheetsFromExcelWorkbook(WorkBook workbook)
{
return workbook.WorkSheets;
Expand All @@ -45,6 +48,7 @@ public static WorkSheet[] GetWorksheetsFromExcelWorkbook(WorkBook workbook)
/// <param name="name"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkSheet GetExcelWorksheetByName(WorkBook workbook, string name)
{
return workbook.GetWorksheetByName(name);
Expand All @@ -56,6 +60,7 @@ public static WorkSheet GetExcelWorksheetByName(WorkBook workbook, string name)
/// <param name="worksheet"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static object[][] GetDataFromExcelWorksheet(WorkSheet worksheet)
{
return worksheet.Data;
Expand All @@ -71,6 +76,7 @@ public static object[][] GetDataFromExcelWorksheet(WorkSheet worksheet)
/// <param name="data"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkSheet WriteDataToExcelWorksheet(
WorkSheet worksheet, int startRow = 0, int startColumn = 0, object[][] data = null)
{
Expand All @@ -87,6 +93,7 @@ public static WorkSheet WriteDataToExcelWorksheet(
/// <param name="name"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkSheet AddExcelWorksheetToWorkbook(WorkBook workbook, string name)
{
return new WorkSheet(workbook, name);
Expand All @@ -97,6 +104,7 @@ public static WorkSheet AddExcelWorksheetToWorkbook(WorkBook workbook, string na
/// </summary>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkBook NewExcelWorkbook()
{
return new WorkBook("");
Expand All @@ -109,6 +117,7 @@ public static WorkBook NewExcelWorkbook()
/// <param name="filename"></param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static WorkBook SaveAsExcelWorkbook(WorkBook workbook, string filename)
{
return new WorkBook(workbook, filename);
Expand All @@ -127,6 +136,7 @@ public static WorkBook SaveAsExcelWorkbook(WorkBook workbook, string filename)
/// <returns name="data">Rows of data from the Excel worksheet.</returns>
/// <search>office,excel,spreadsheet,ifequalreturnindex</search>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static object[][] ReadFromFile(FileInfo file, string sheetName, bool readAsStrings = false, bool showExcel = true)
{
object[][] data;
Expand Down Expand Up @@ -178,6 +188,7 @@ public static object[][] Read(string filePath, string sheetName)
/// <returns name="data">Data written to the spreadsheet.</returns>
/// <search>office,excel,spreadsheet</search>
[IsVisibleInDynamoLibrary(false)]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static object[][] WriteToFile(string filePath, string sheetName, int startRow, int startCol, object[][] data, bool overWrite = false)
{
return ExcelWriteUtils.WriteData(filePath, sheetName, startRow, startCol, data, overWrite);
Expand All @@ -201,6 +212,7 @@ public static partial class Data
/// <param name="showExcel">Toggle to show excel's main window</param>
/// <returns name="data">Rows of data from the Excel worksheet</returns>
/// <search>office,excel,spreadsheet,ifequalreturnindex</search>
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static object[][] ImportExcel(FileInfo file, string sheetName, bool readAsStrings = false, bool showExcel = true)
{
return Excel.ReadFromFile(file, sheetName, readAsStrings, showExcel);
Expand All @@ -223,7 +235,7 @@ public static object[][] ImportExcel(FileInfo file, string sheetName, bool readA
/// <param name="overWrite">True to overwrite file, false not to overwrite</param>
/// <returns name="data">Data written to the spreadsheet</returns>
/// <search>office,excel,spreadsheet</search>
[Obsolete("Use ExportToExcel instead.")]
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static object[][] ExportExcel(string filePath, string sheetName, int startRow, int startColumn, object[][] data, bool overWrite = false)
{
return ExcelWriteUtils.WriteData(filePath, sheetName, startRow, startColumn, data, overWrite);
Expand All @@ -247,6 +259,7 @@ public static object[][] ExportExcel(string filePath, string sheetName, int star
/// <param name="writeAsString">Toggle to switch between writing Excel file as strings</param>
/// <returns name="data">Rows of data from the Excel worksheet</returns>
/// <search>office,excel,spreadsheet</search>
[NodeObsolete("ExcelInteropObsoleteNode", typeof(Properties.Resources))]
public static object[][] ExportToExcel(string filePath, string sheetName, int startRow, int startColumn, object[][] data, bool overWrite = false, bool writeAsString = false)
{
return ExcelWriteUtils.WriteData(filePath, sheetName, startRow, startColumn, data, overWrite, writeAsString);
Expand Down
18 changes: 18 additions & 0 deletions src/Libraries/DSOffice/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Libraries/DSOffice/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ExcelInteropObsoleteNode" xml:space="preserve">
<value>This node is obsolete and will be removed in a future version of Dynamo, please use the corresponding one that is OpenXML based.</value>
</data>
<data name="ReadObsolete" xml:space="preserve">
<value>Use File.FromPath -&gt; Excel.ReadFromFile node instead.</value>
</data>
<data name="StreamWriterNotFoundException" xml:space="preserve">
<value>The file or directory cannot be found</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/Libraries/DSOffice/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ExcelInteropObsoleteNode" xml:space="preserve">
<value>This node is obsolete and will be removed in a future version of Dynamo, please use the corresponding one that is OpenXML based.</value>
</data>
<data name="ReadObsolete" xml:space="preserve">
<value>Use File.FromPath -&gt; Excel.ReadFromFile node instead.</value>
</data>
<data name="StreamWriterNotFoundException" xml:space="preserve">
<value>The file or directory cannot be found</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion test/DynamoCoreTests/ExcelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void GetLibrariesToPreload(List<string> libraries)
base.GetLibrariesToPreload(libraries);
}

[Test]
[Test, Category("ExcelTestInterop")]
public void TestExcel()
{
// (1..5) + 1;
Expand Down
Loading

0 comments on commit d1dd01f

Please sign in to comment.