Hello,
I’m trying to code a node to read datas from an excel workbook.
Make some trials in Visual Studio : no problem to have an array of values in string format.
The same code in a dynamic template give me more headaches.
The conversion of the object values doesn’t work the same way.
in Visual “Cells.Value.ToString()” is ok but not in vvvv.
It seems also that the quit command doesn’t work in vvvv.
Thank you if you take a look to my code and sorry for the heresy in it : I’m a real beginner.
- region usings
using System;
using System.ComponentModel.Composition;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using MsXl = Microsoft.Office.Interop.Excel;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Utils.VColor;
using VVVV.Utils.VMath;
using VVVV.Core.Logging;
- endregion usings
namespace VVVV.Nodes
{
#region PluginInfo
[PluginInfo(Name = "ExcelReader1", Category = "Value", Help = "I read your fuckin XLS file", Tags = "")](PluginInfo(Name = "ExcelReader1", Category = "Value", Help = "I read your fuckin XLS file", Tags = ""))
#endregion PluginInfo
public class ValueExcelReader1Node : IPluginEvaluate
{
#region fields & pins
[Input("workbook",StringType = StringType.Filename ,IsSingle = true)](Input("workbook",StringType = StringType.Filename ,IsSingle = true))
public ISpread<string> xlfile;
[Input("Sheet", DefaultValue = 1.0)](Input("Sheet", DefaultValue = 1.0))
public ISpread<int> xlsheet;
[Input("Row", DefaultValue = 1.0)](Input("Row", DefaultValue = 1.0))
public ISpread<int> row;
[Input("Clmn", DefaultValue = 1.0)](Input("Clmn", DefaultValue = 1.0))
public ISpread<int> clmn;
[Input("Read", DefaultValue = 0)](Input("Read", DefaultValue = 0))
public ISpread<bool> xlread;
[Output("Output")](Output("Output"))
public ISpread<string> FOutput;
[Import()](Import())
public ILogger FLogger;
#endregion fields & pins
//called when data for any output pin is requested
public void Evaluate(int SpreadMax)
{
FOutput.SliceCount = SpreadMax;
string filename = @xlfile[0](0);
if(xlread[0](0))
{
MsXl.Application apxl = new MsXl.Application();
MsXl.Workbook xlwb = apxl.Workbooks.Open(filename, ReadOnly: true);
MsXl.Worksheet xlws = (MsXl.Worksheet) xlwb.ActiveSheet;
object[]() FromXl = new object[SpreadMax](SpreadMax);
for (int i = 0; i < SpreadMax; i++)
{
FromXl[i](i) = xlws.Cells[row[i](row[i), clmn[i](i)];
if (FromXl[i](i).Value2 == null)
{
FOutput[i](i) = null;
}
else
{
FOutput[i](i) = FromXl[i](i).Value.ToString();
}
}
xlwb.Close();
apxl.Quit();
}
//FLogger.Log(LogType.Debug, "hi tty!");
}
}
}