protected override void Execute(NativeActivityContext context) { string filePath = FilePath.Get(context); XLExcelContextInfo customExcelCtx = new XLExcelContextInfo() { Path = filePath, }; if (Body != null) { context.ScheduleAction <XLExcelContextInfo>(Body, customExcelCtx, OnCompleted, OnFaulted); } }
protected override void Execute(CodeActivityContext context) { //get Excel context XLExcelContextInfo customContext = Utils.GetXLExcelContextInfo(context); //retrieve the parameters from the Context string filePath = customContext.Path; //retrieve the parameters from the Context string range = Range.Get(context); string sheetName = SheetName.Get(context); bool addHeaders = Headers;//.Get(context); //excel range init ExcelRange excelRange = new ExcelRange(range); DataTable result = Utils.ReadSAXRange(excelRange, filePath, sheetName, addHeaders); //"C:\\Users\\bucur\\source\\repos\\ExcelSheetExtensionClasses\\TestExcelExtensions\\TestFiles\\LALALA.xlsx", "Sheet1", false); //set the result Result.Set(context, result); }
protected override void Execute(CodeActivityContext context) { WorkflowDataContext dc = context.DataContext; //get Excel context XLExcelContextInfo customContext = Utils.GetXLExcelContextInfo(context); //retrieve the parameters from the Context string filePath = customContext.Path; string sheetName = SheetName.Get(context); string rowNum = ""; //open file using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(filePath, true)) { WorkbookPart workbookPart = myDoc.WorkbookPart; //determine ID of the Sheet string relId = workbookPart.Workbook.Descendants <Sheet>().First(s => sheetName.Equals(s.Name)).Id; if (String.IsNullOrEmpty(relId)) { throw new Exception("Could not indentify the Excel Sheet"); } //open reader for Sheet WorksheetPart worksheetPart = workbookPart.GetPartById(relId) as WorksheetPart; OpenXmlReader reader = OpenXmlReader.Create(worksheetPart); //read the XML objects until we reach the rows while (reader.Read()) { //check if current elem is row if (reader.ElementType == typeof(Row)) { //loop through row siblings do { if (reader.HasAttributes) { //at each step, read the current rowNum rowNum = reader.Attributes.First(a => a.LocalName == "r").Value; } } while (reader.ReadNextSibling()); break; } } } int result; //convert the result to Int and pass it as an output argument if (Int32.TryParse(rowNum, out result)) { NumberOfRows.Set(context, result); } else { throw new Exception("Unable to parse the line number"); } }